distributed test do not work with pytest_generate_tests (Windows)

Issue #76 resolved
Sorin Ionuț Sbârnea created an issue

Running the below code with py.test -n 3 file.py does run sequential instead of using the 3 processes.

I checked the task manager and I do not see more than one sleep.exe process at a time.

{{{

!python

import os, sys

def pytest_generate_tests(metafunc): for i in range(1,5): metafunc.addcall(funcargs=dict(i=i))

def test_parsing(i): ret = os.system('sleep 3') assert ret==0

def test_parsing2(i): ret = os.system('sleep 3') assert ret==0 }}}

Running results {{{

!text

python: platform win32 -- Python 2.6.4 -- pytest-1.1.1 -- C:\Python26\python.exe test object 1: C:\dev\py\cores\tests [gw0] popen -- platform win32, Python 2.6.4-final-0 cwd: C:\dev\py\cores- C:\Python26\python.exe [gw1] popen -- platform win32, Python 2.6.4-final-0 cwd: C:\dev\py\cores- C:\Python26\python.exe [gw2] popen -- platform win32, Python 2.6.4-final-0 cwd: C:\dev\py\cores- C:\Python26\python.exe [gw1] txnode ready to receive tests [gw2] txnode ready to receive tests [gw0] txnode ready to receive tests [gw1] PASS tests\test_sleep.py:9: test_parsing.test_parsing[0] [gw1] PASS tests\test_sleep.py:9: test_parsing.test_parsing[1] [gw1] PASS tests\test_sleep.py:9: test_parsing.test_parsing[2] [gw1] PASS tests\test_sleep.py:9: test_parsing.test_parsing[3] [gw1] PASS tests\test_sleep.py:13: test_parsing2.test_parsing2[0] [gw1] PASS tests\test_sleep.py:13: test_parsing2.test_parsing2[1] [gw1] PASS tests\test_sleep.py:13: test_parsing2.test_parsing2[2] [gw1] PASS tests\test_sleep.py:13: test_parsing2.test_parsing2[3]

}}}

Comments (9)

  1. Sorin Ionuț Sbârnea reporter

    I made the same test on Linux and I get the same results: always using only gw0

  2. Holger Krekel repo owner

    Hi Sorin,

    py.test internally sends tests in bunches of 15 - so if you are below that they all land at the first host.

    This magic default makes some sense for quick unit-test settings where but not so much for larger functional tests.

    However, i am going to think and experiment a bit this weekend how to get rid of this magic variable - else i make it configurable.

    cheers, holger

  3. Sorin Ionuț Sbârnea reporter

    Thank! How should I know this - this is not documented and I think it should be. For example currently I have 13 tests and all of them take a lot of time but not much CPU usage so I would want to run them on parallel.

    Do you know a way of using Python to hacking the variable MAXITEMSPERHOST from the test file?

  4. Holger Krekel repo owner

    it's not documented, true. sorry about that. As a workaround you could put this in a conftest, i think:

    import py
    if py.__version__.startswith("1.1"):
        from py.impl.test.dist import dsession
        dsession.DSession.MAXITEMSPERHOST = 1
    

    Does this work for you?

  5. Sorin Ionuț Sbârnea reporter

    Thanks, this worked and cut the total time to 50%. BTW, is it possible to configure the number of threads from inside the script or this is mandatory to be specified from the command line?

  6. Holger Krekel repo owner

    you could create a conftest.py along the test file and put this into it:

    # conftest.py
    option_dist = "load"
    option_tx = ['popen'] * 3
    

    there is no way to put it into the test file directly because when the test file is imported, the command line has already been parsed and the session configuration been done.

    cheers, holger

  7. Holger Krekel repo owner

    Hi Sorin,

    i think the original issue is fixed with the just released 1.2.0 and pytest-xdist plugin. There is no MAXITEMS setting anymore, things should just effecitvely work by default now. xdist will split tests more evenly across the nodes now.

    cheers, holger

  8. Log in to comment