Skip to content

Commit

Permalink
Merge pull request #15 from Quansight-Labs/fix_skipif_decorator
Browse files Browse the repository at this point in the history
Ensure that pytest.mark.skipif works
  • Loading branch information
andfoy authored Nov 6, 2024
2 parents 7dc436e + f25c85b commit 1ea2c91
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/pytest_run_parallel/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
import threading
import types

import _pytest.outcomes
import pytest
from _pytest.outcomes import Failed, Skipped

try:
import numpy as np
Expand Down Expand Up @@ -63,10 +63,10 @@ def closure(*args, **kwargs):
pass
except Exception as e:
errors.append(e)
except Skipped as s:
except _pytest.outcomes.Skipped as s:
nonlocal skip
skip = s.msg
except Failed as f:
except _pytest.outcomes.Failed as f:
nonlocal failed
failed = f

Expand Down Expand Up @@ -107,7 +107,11 @@ def pytest_itemcollected(item):
n_iterations = int(m.args[0])

if n_workers > 1 or n_iterations > 1:
original_globals = item.obj.__globals__
item.obj = wrap_function_parallel(item.obj, n_workers, n_iterations)
for name in original_globals:
if name not in item.obj.__globals__:
item.obj.__globals__[name] = original_globals[name]


@pytest.fixture
Expand Down
23 changes: 23 additions & 0 deletions tests/test_run_parallel.py
Original file line number Diff line number Diff line change
Expand Up @@ -489,3 +489,26 @@ def test_should_yield_marker_threads(num_iterations):
"*::test_should_yield_marker_threads PASSED*",
]
)


def test_skipif_marker_works(pytester):
# create a temporary pytest test module
pytester.makepyfile("""
import pytest
VAR = 1
@pytest.mark.skipif('VAR == 1', reason='VAR is 1')
def test_should_skip():
pass
""")

# run pytest with the following cmd args
result = pytester.runpytest("--parallel-threads=10", "-v")

# fnmatch_lines does an assertion internally
result.stdout.fnmatch_lines(
[
"*::test_should_skip SKIPPED*",
]
)

0 comments on commit 1ea2c91

Please sign in to comment.