我正在运行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件事。
即使我在pytest中添加了标志,也无法获取日志.ini
[测试]
添加选择= -V -S
log_cli=真
log_cli_level=调试
log_level=调试
日志是否存储在某个地方?
- 两个环境都没有平行运行。
我正在关闭它,因为我通过 pytest-paralell 插件得到了答案。
pytest tests/test_TC300457.py --tests-per-worker auto --env micqe3 --env micqe1