Skip to content

pytest-harvest does not work with python-xdist #32

Closed
@larsks

Description

@larsks

pytest-harvest is unable to work in an environment with parallel tests. Any tests that make use of the harvest results fixtures (module_results_df, session_results_df, etc) are simply scheduled in parallel with other tests, and will in general complete before the other tests have finished running.

Consider the following example:

import pytest
import time


@pytest.mark.parametrize('instance', range(5))
def test_example(instance):
    time.sleep(5)
    assert True


def test_results(session_results_df):
    with open('results.csv', 'w') as fd:
        fd.write(session_results_df.to_csv())

If we run this in an environment with pytest-xdist like this:

pytest -v -n8 test_harvest.py

We see that all the tests get scheduled at the same time:

test_harvest.py::test_example[1] 
test_harvest.py::test_example[3] 
test_harvest.py::test_example[0] 
test_harvest.py::test_example[2] 
test_harvest.py::test_example[4] 
test_harvest.py::test_results 
[gw5] [ 16%] PASSED test_harvest.py::test_results 
[gw0] [ 33%] PASSED test_harvest.py::test_example[0] 
[gw3] [ 50%] PASSED test_harvest.py::test_example[3] 
[gw4] [ 66%] PASSED test_harvest.py::test_example[4] 
[gw2] [ 83%] PASSED test_harvest.py::test_example[2] 
[gw1] [100%] PASSED test_harvest.py::test_example[1] 

And at the end, results.csv contains:

test_id

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions