Quansight-Labs / pytest-run-parallel

A simple pytest plugin to run tests concurrently
MIT License
6 stars 2 forks source link

`--run-parallel` doesn't work well with old style `@pytest.mark.skipif("expr")` #13

Closed colesbury closed 2 weeks ago

colesbury commented 2 weeks ago

Note this occurs when @pytest.mark.skipif("expr") is called with a string to be evaluated.

m1.py

GLOBAL_VAR = True

test_m1.py

import pytest
import m1

@pytest.mark.skipif("m1.GLOBAL_VAR", reason="GLOBAL_VAR is True")
def test_test1():
    print("test1")

Works okay when run without --parallel-threads:

> pytest test_m1.py
SKIPPED [1] tests/test_m1.py:4: GLOBAL_VAR is True

But doesn't work when run with --parallel-threads:

> pytest test_m1.py --parallel-threads=2

============================================================================= ERRORS =============================================================================
__________________________________________________________________ ERROR at setup of test_test1 __________________________________________________________________
name 'm1' is not defined

During handling of the above exception, another exception occurred:
Error evaluating 'skipif' condition
    m1.GLOBAL_VAR
NameError: name 'm1' is not defined
andfoy commented 2 weeks ago

I confirm the validity of this issue, this is due to the wrapped functions not carrying over the global variables of the original test function, a PR with the changes is underway.

@lysnikolaou I would suggest freezing the release until this change comes in