我有一个我想连续运行的脚本列表。我该怎么做?
我一般都用过
from subprocess import call
call(["python","C:\\11.py"])
但我想在pytest中做到这一点。
A.朋友
print('h')
if __name__ == '__main__':
test_add()
test_add.朋友
print('k')
if __name__ == '__main__':
test_add2()
test_add2.朋友
print('done')
如果你有一个使用__init__.py
的python包,请参阅These docs了解更多细节。
在最基本的情况下,您有两个文件。你的模块和pytest模块。 ProjectA可以将它们放在同一个文件夹中。
ProjectA/
a.py
test_a.py
啊.朋友
def some_code():
print('code to be tested')
test_啊.朋友
import a
def test_some_code():
a.some_code()
然后运行代码:
$ cd path/to/ProjectA
$ pytest