Skip to content

Commit f056109

Browse files
committed
add new test and rearrange to fix existing test
1 parent 263bd94 commit f056109

2 files changed

Lines changed: 43 additions & 6 deletions

File tree

src/pytest_run_parallel/plugin.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,12 @@ def pytest_collection_finish(self, session):
254254
self._handle_collected_item(item)
255255

256256
def _handle_collected_item(self, item):
257+
if isinstance(item, _pytest.doctest.DoctestItem):
258+
self._mark_test_thread_unsafe(
259+
item, "is a doctest (pytest-run-parallel does not support doctests)"
260+
)
261+
return
262+
257263
if getattr(item, "obj", None) is None:
258264
if not hasattr(item, "_parallel_custom_item"):
259265
warnings.warn(
@@ -273,12 +279,6 @@ def _handle_collected_item(self, item):
273279
)
274280
return
275281

276-
if isinstance(item, _pytest.doctest.DoctestItem):
277-
self._mark_test_thread_unsafe(
278-
item, "is a doctest (pytest-run-parallel does not support doctests)"
279-
)
280-
return
281-
282282
n_workers, parallel_threads_marker_used = get_num_workers(item)
283283
if n_workers < 0:
284284
raise ValueError("parallel-threads cannot be negative")

tests/test_run_parallel.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -615,6 +615,43 @@ def test_incompatible_item():
615615
assert result.parseoutcomes()["warnings"] == 1
616616

617617

618+
def test_incompatible_test_item_2(pytester):
619+
pytester.makeconftest("""
620+
import inspect
621+
import pytest
622+
623+
class CustomItem(pytest.Item):
624+
def __init__(self, name, parent=None, config=None, session=None, nodeid=None, function=None, **kwargs):
625+
super().__init__(name, parent, config, session, nodeid, **kwargs)
626+
self.function = function
627+
self.obj = None
628+
629+
def runtest(self):
630+
self.function()
631+
632+
@pytest.hookimpl(wrapper=True, trylast=True)
633+
def pytest_pycollect_makeitem(collector, name: str, obj: object):
634+
result = yield
635+
if not inspect.isfunction(obj):
636+
return result
637+
return CustomItem.from_parent(name=name, parent=collector, function=obj)
638+
""")
639+
640+
pytester.makepyfile("""
641+
import pytest
642+
643+
def test_incompatible_item():
644+
assert True
645+
""")
646+
result = pytester.runpytest("--parallel-threads=10", "-v", "-W", "default")
647+
result.stdout.fnmatch_lines(
648+
[
649+
"*::test_incompatible_item PASSED*",
650+
]
651+
)
652+
assert result.parseoutcomes()["warnings"] == 1
653+
654+
618655
def test_known_incompatible_test_item_doesnt_warn(pytester):
619656
pytester.makeconftest("""
620657
import inspect

0 commit comments

Comments
 (0)