0

I am running pytest_addoption hook along with pytest xdist plugin

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'))

Running my command line like ...

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

The command is executing 2 times with ENV1 and 2 times with ENV2 paralelly. Not sure why !

Is this a bug ? OR Am I executing wrongly ?

(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]$ 

As you see I have 4 test cases being PASSED while I am expecting 2 environments to be executed.

2 more things.

  1. Unable to get the logs even though I have added flags in my pytest.ini

    [pytest]

    addopts = -v -s

    log_cli=true

    log_cli_level=DEBUG

    log_level=DEBUG

Are the logs getting stored somewhere ?

  1. Both the environments are not running paralelly.
MrBean Bremen
  • 14,916
  • 3
  • 26
  • 46
Bharath Kashyap
  • 343
  • 2
  • 5
  • 14

1 Answers1

0

I am closing this as I got the answer via pytest-paralell plugin.

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

Bharath Kashyap
  • 343
  • 2
  • 5
  • 14