我有一个项目,每个应用程序都有一个tests模块,如下所示:
app1/
tests/
__init__.py
# whatever test files are
app2/
tests/
__init__.py
# whatever test files are
在项目根目录中也有您可以猜到的项目包。它有一个testing子包,它包含模型和字段的基本测试用例,当然还有如下所示的固定装置:
myproject/
__init__.py
# settings and related files, you know
testing/
__
我使用的是Pytest,我有一个场景,其中必须调用fixtureA并在fixtureB之前分配一些东西。和A类一样,有更多的B类、C类、D类等,具有不同的数据类型,因此some_data.type不是常数!
就像这样:
@pytest.fixture(scope='module')
def fixtureB(some_data):
# this needs to happen after A.before()
some_data.some_calc_after_A()
class A:
@pytest.fixture(scope='class')
在运行测试之后,pytest中有一个概述: =在1.11秒内通过了=7 我喜欢访问pytest末尾的时间(这里是1.11)。 我已经在这里找到了一些有用的信息: How can I access the overall test result of a pytest test run during runtime? 但与总体测试运行时间不匹配。 我尝试使用def pytest_sessionfinish(会话,退出状态) 我在那里没有找到总的持续时间。 看起来这个值在RunResult对象中。https://docs.pytest.org/en/latest/_modules/_pytest
我试图在pytest脚本中使用模块级别的函数(而不是直接为变量赋值)来定义字符串,该函数将在范围=“模块”的夹具中使用。问题是,当在模块级别上使用函数时,在pytest收集阶段对其进行评估--并且当在带有几个脚本的文件夹上运行pytest时,该夹具使用最后一个评估值。
是否有其他方法在每个脚本的模块级别上设置字符串?
到目前为止,我还没有做到这一点:
my_script1.py:
import env_var as env
env.set_my_string('This string will be used in the module fixture')
test_fir
在Pytest中,我尝试做以下事情,我需要保存之前的结果,并在多次迭代中将当前/当前结果与以前的结果进行比较。我已经做到了以下几个方面:
@pytest.mark.parametrize("iterations",[1,2,3,4,5]) ------> for 5 iterations
@pytest.mark.parametrize("clsObj",[(1,2,3)],indirect = True) ---> here clsObj is the instance. (clsObj.currentVal, here clsObj gets
通过传递在conftest.py中定义的@pytest.mark.parametrize中定义的夹具,我得到了以下错误:
pytest --alist="0220,0221" test_1.py -v -s
NameError: name 'alist' is not defined
conftest.py:
def pytest_addoption(parser):
parser.addoption("--alist", action="store")
@pytest.fixture
def alist(request
我想访问从非测试类中传递给pytest的命令行参数。
我将以下内容添加到我的conftest.py文件中
def pytest_addoption(parser): # pragma: no cover
"""Pytest hook to add custom command line option(s)."""
group = parser.getgroup("Test", "My test option")
group.addoption(
"--stack",
h