pytest xdist插件与pytest_addoption挂钩异常运行

时间:2019-06-24 10:55:56

标签: python pytest

我正在与pytest xdist插件一起运行pytest_addoption钩子

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. 两个环境都没有并行运行。

1 个答案:

答案 0 :(得分:0)

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

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