简体   繁体   English

pytest 没有运行 conftest.py 来获取自定义命令参数

[英]pytest is not running conftest.py to pick up custom command args

In a project im working on we have a step where we export a csv before exporting we run a regression test step against the report using pytest.在我正在进行的一个项目中,我们有一个步骤,我们在导出之前导出一个 csv,我们使用 pytest 对报告运行回归测试步骤。 pytest is invoked using the following command pytest 使用以下命令调用

    def _invoke_pytest(self):
    pytest.main(['src/tests/regression/regression_tests.py'
                ,"-m",self.expectations_suite
                ,'--sample', self.sample_filepath
                ,'--expectations',self.expectations_suite_filepath
                ,'--report-log',self.logs_report_filepath])

--sample and --expectations are custom args defined in the conftest.py using the following --sample 和 --expectations 是在 conftest.py 中使用以下定义的自定义参数

def pytest_addoption(parser):
    parser.addoption("--sample", default=False)
    parser.addoption("--expectations", default=False)

when calling this code locally it works pytest finds the conf but when inside a docker container it doesnt pick up the conftest and therefore fails on running pytest.当在本地调用此代码时,它可以工作 pytest 找到 conf,但是当在 docker 容器内时,它不会获取 conftest,因此在运行 pytest 时失败。 a simplified folder layout is as follows一个简化的文件夹布局如下

src/
├─ main/
│  ├─ export
│  ├─ invoke_pytest
├─ test/
│  ├─ regression/
│  │  ├─ conftest

any help would be greatly appreciated, thanks任何帮助将不胜感激,谢谢

通过将 conftest 移动到 src 文件夹中允许 pytest 找到它,该问题已得到解决

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 PyTest 中有没有办法将命令行参数直接传递给 conftest.py? - Is there a way in PyTest to pass command line arguments to conftest.py directly? 在Robot Framework上是否有conftest.py pytest等价物 - Is there a conftest.py pytest equivalent on Robot Framework 在pytest中,conftest.py文件有什么用? - In pytest, what is the use of conftest.py files? 使用 Pytest 和 conftest.py 文件时未显示断言错误的预期结果 - Expected results of Assertion Errors are not showing up when using Pytest and conftest.py file 为什么 pytest 在仅运行一部分测试时不加载 conftest.py? - Why doesn't pytest load conftest.py when running only a subset of tests? 如何在不修改 conftest.py 的情况下在 pytest 中使用命令行参数 - How to use command line arguments in pytest without modifying conftest.py 如何在pytest中的conftest.py文件中传递命令行选项值 - How to pass command line option value within conftest.py file in pytest 如何在 cmd.exe 中命令变量值从 conftest.py 到 pytest - how to command variables values from conftest.py to pytest in cmd.exe 在父项目上运行 pytest 时,如何忽略 git 子模块(例如 submodule/conftest.py)根目录下的 conftest.py 文件? - How do I ignore a conftest.py file at the root of a git submodule (e.g. submodule/conftest.py) when running pytest on the parent project? 在非根 conftest.py 中使用 pytest_addoptions - Using pytest_addoptions in a non-root conftest.py
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM