我有一些在我所有的 PyTest 中使用的通用代码。我想将完整的代码保存在任何文件中并在运行时加载它。可以使用 Python 吗?
例如:
def teardown_method(self, method):
print "This is tear down method"
def setup_method(self, method):
print "This is setup method"
我有一些在我所有的 PyTest 中使用的通用代码。我想将完整的代码保存在任何文件中并在运行时加载它。可以使用 Python 吗?
例如:
def teardown_method(self, method):
print "This is tear down method"
def setup_method(self, method):
print "This is setup method"
除了简单地使用import
,对于您展示的示例(设置/拆卸),您通常会使用pytest 固定装置,并将它们放在 aconftest.py
中以在测试之间共享它们。