如何使用pytest调用另一个脚本

问题描述 投票:0回答:1

我有一个我想连续运行的脚本列表。我该怎么做?

我一般都用过

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')
python pytest
1个回答
0
投票

如果你有一个使用__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
© www.soinside.com 2019 - 2024. All rights reserved.