0

我正在运行 pytest_addoption 钩子和 pytest xdist 插件

def pytest_addoption(parser):
    parser.addoption("--env", action="append", default=[], help="list of env's to pass to test functions")

def pytest_generate_tests(metafunc):
    if 'env' in metafunc.fixturenames: metafunc.parametrize("env", metafunc.config.getoption('env'))

像...一样运行我的命令行

pytest tests/test_tests.py --tx popen//env:NAME=ENV1 --env "ENV1" --tx popen//env:NAME=ENV2 --env "ENV2" --dist=each

该命令使用 ENV1 执行 2 次,使用 ENV2 并行执行 2 次。不知道为什么!

这是一个错误吗?还是我执行错误?

(venv) [tivo@localhost src]$ pytest tests/test_TC300457.py --tx popen//env:NAME=1 --env "micqe1" --tx popen//env:NAME=2 --env "micqe3" --dist=each
===================================================================== test    session starts     ======================================================================
platform linux -- Python 3.4.4, pytest-4.5.0, py-1.8.0, pluggy-0.11.0 -- /home/tivo/workspace/ServicePortal/autotestscripts/CAT/scripts/ServerQE/brat/venv/bin/python3
cachedir: .pytest_cache
rootdir: /home/tivo/workspace/ServicePortal/autotestscripts/CAT/scripts/ServerQE/brat/src, inifile: pytest.ini
plugins: xdist-1.28.0, remotedata-0.3.1, pipeline-0.3.0, parallel-0.0.9, forked-1.0.2, flake8-1.0.4, cov-2.7.1

[gw0] linux Python 3.4.4 cwd: /home/tivo/workspace/ServicePortal/autotestscripts/CAT/scripts/ServerQE/brat/src
[gw1] linux Python 3.4.4 cwd: /home/tivo/workspace/ServicePortal/autotestscripts/CAT/scripts/ServerQE/brat/src
[gw0] Python 3.4.4 (default, Mar 19 2018, 14:47:20)  -- [GCC 4.4.7 20120313 (Red Hat 4.4.7-18)]
[gw1] Python 3.4.4 (default, Mar 19 2018, 14:47:20)  -- [GCC 4.4.7 20120313 (Red Hat 4.4.7-18)]
gw0 [2] / gw1 [2]
scheduling tests via EachScheduling

  tests/test_TC300457.py::TestPortalSP01::test_TC_300457_ValidateAlerts[micqe1] 
[gw0] PASSED      tests/test_TC300457.py::TestPortalSP01::test_TC_300457_ValidateAlerts[micqe1] 
[gw1] PASSED     tests/test_TC300457.py::TestPortalSP01::test_TC_300457_ValidateAlerts[micqe1] 
tests/test_TC300457.py::TestPortalSP01::test_TC_300457_ValidateAlerts[micqe3] 
[gw0] PASSED     tests/test_TC300457.py::TestPortalSP01::test_TC_300457_ValidateAlerts[micqe3] 
[gw1] PASSED         tests/test_TC300457.py::TestPortalSP01::test_TC_300457_ValidateAlerts[micqe3] 


================================================================== 4 passed in 64.71 seconds ===================================================================
(venv) [tivo@localhost src]$ 

如您所见,我有 4 个测试用例通过,而我期望执行 2 个环境。

还有2件事。

  1. 即使我在 pytest.ini 中添加了标志,也无法获取日志

    [pytest]

    addopts = -v -s

    log_cli=true

    log_cli_level=调试

    log_level=调试

日志是否存储在某处?

  1. 两种环境都没有并行运行。
4

1 回答 1

0

当我通过 pytest-paralell 插件得到答案时,我将关闭它。

pytest 测试/test_TC300457.py --tests-per-worker auto --env micqe3 --env micqe1

于 2019-06-24T11:55:13.583 回答