我已经用conda安装了python。
pytest --version
This is pytest version 3.0.5, imported from /home/fabiano/anaconda3/lib/python3.6/site-packages/pytest.py
我的测试脚本
def tc1():
given="49276d206b696c6c696e6720796f757220627261696e206c696b65206120706f69736f6e6f7573206d757368726f6f6d"
expected=b"SSdtIGtpbGxpbmcgeW91ciBicmFpbiBsaWtlIGEgcG9pc29ub3VzIG11c2hyb29t"
assert base64.b64encode(bytes.fromhex(given)) == expected
我已导入pytest
import pytest
我正在尝试使用pytest的一些东西。但是当我尝试使用Python shell时,我遇到了类似的问题
testset.py
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'testset' is not defined
在我的shell中 pytest
<module 'pytest' from '/home/fabiano/anaconda3/lib/python3.6/site-packages/pytest.py'>
我应该在哪里保存testset.py文件?
答案 0 :(得分:4)
pytest测试发现。基本步骤列在documentation
中test_*.py
或*_test.py
。def test_*
为了测试,请将以下代码放在文件test_set.py
中:
import base64
def test_tc1():
given="49276d206b696c6c696e6720796f757220627261696e206c696b65206120706f69736f6e6f7573206d757368726f6f6d"
expected=b"SSdtIGtpbGxpbmcgeW91ciBicmFpbiBsaWtlIGEgcG9pc29ub3VzIG11c2hyb29t"
assert base64.b64encode(bytes.fromhex(given)) == expected
导航到包含文件test_set.py
的目录并执行pytest命令:
pytest
预期产出:
user@pc:/tmp/test_dir $ pytest .
============================= test session starts ==============================
platform linux -- Python 3.5.2+, pytest-3.0.3, py-1.4.31, pluggy-0.4.0
rootdir: /tmp/test_dir , inifile: collected 1 items
test_set.py .
=========================== 1 passed in 0.01 seconds ===========================