小编ste*_*ius的帖子

pytest:如何制作专用的测试目录

我想要以下项目结构:

|--folder/
|  |--tests/
|  |--project/
Run Code Online (Sandbox Code Playgroud)

我们写一个简单的例子:

|--test_pytest/
|  |--tests/
|  |  |--test_sum.py
|  |--t_pytest/
|  |  |--sum.py
|  |  |--__init__.py
Run Code Online (Sandbox Code Playgroud)

总和.py:

def my_sum(a, b):
    return a + b
Run Code Online (Sandbox Code Playgroud)

test_sum.py:

from t_pytest.sum import my_sum
def test_my_sum():
    assert my_sum(2, 2) == 5, "math still works"
Run Code Online (Sandbox Code Playgroud)

让我们运行它:

test_pytest$ py.test ./
========== test session starts ===========
platform linux -- Python 3.4.3, pytest-2.9.2, py-1.4.31, pluggy-0.3.1
rootdir: /home/step/test_pytest, inifile: 
collected 0 items / 1 errors 

================= ERRORS =================
___ ERROR collecting tests/test_sum.py ___
tests/test_sum.py:1: in …
Run Code Online (Sandbox Code Playgroud)

python testing project-structure pytest

4
推荐指数
1
解决办法
5727
查看次数

Python日志模块加密

我有一个带日志记录的python脚本。现在我想使用 pycrypto 使用 AES 加密日志。

import logging
import base64
from Crypto.Cipher import AES
aes = AES.new(cryptoKey)
logging.basicConfig(filename='example.log',level=logging.DEBUG) #  file name, not custom file
logging.info('text')
Run Code Online (Sandbox Code Playgroud)

我想base64.b64encode(aes.encrypt('#logging text#'))在将其写入 log 之前使用。什么是最有效的方式来做到这一点?

python encryption logging python-2.7

4
推荐指数
1
解决办法
2029
查看次数