44import threading
55import warnings
66
7+ import _pytest .doctest
78import _pytest .outcomes
89import pytest
910
@@ -142,6 +143,27 @@ def closure(*args, **kwargs):
142143
143144@pytest .hookimpl (trylast = True )
144145def pytest_itemcollected (item ):
146+ if not hasattr (item , "obj" ):
147+ if not hasattr (item , "_parallel_custom_item" ):
148+ warnings .warn (
149+ f"Encountered pytest item with type { type (item )} with no 'obj' "
150+ "attribute, which is incompatible with pytest-run-parallel. "
151+ f"Tests using { type (item )} will not run in a thread pool.\n "
152+ "The pytest-run-parallel plugin only supports custom collection "
153+ "tree objects that wrap Python functions stored in an attribute "
154+ "named 'obj'.\n "
155+ "Define a '_parallel_custom_item' attribute on the pytest item"
156+ "instance or class to silence this warning.\n "
157+ "If you do not want to use pytest-run-parallel, uninstall it from "
158+ "your environment."
159+ )
160+ item .add_marker (pytest .mark .parallel_threads (1 ))
161+ return
162+
163+ if isinstance (item , _pytest .doctest .DoctestItem ):
164+ item .add_marker (pytest .mark .parallel_threads (1 ))
165+ return
166+
145167 n_workers = get_num_workers (item .config , item )
146168 fixtures = getattr (item , "fixturenames" , ())
147169
@@ -164,23 +186,6 @@ def pytest_itemcollected(item):
164186 else :
165187 item .add_marker (pytest .mark .parallel_threads (1 ))
166188
167- if not hasattr (item , "obj" ):
168- if hasattr (item , "_parallel_custom_item" ):
169- return
170- warnings .warn (
171- f"Encountered pytest item with type { type (item )} with no 'obj' "
172- "attribute, which is incompatible with pytest-run-parallel. "
173- f"Tests using { type (item )} will not run in a thread pool.\n "
174- "The pytest-run-parallel plugin only supports custom collection "
175- "tree objects that wrap Python functions stored in an attribute "
176- "named 'obj'.\n "
177- "Define a '_parallel_custom_item' attribute on the pytest item"
178- "instance or class to silence this warning.\n "
179- "If you do not want to use pytest-run-parallel, uninstall it from "
180- "your environment."
181- )
182- return
183-
184189 skipped_functions = [
185190 x .split ("." ) for x in item .config .getini ("thread_unsafe_functions" )
186191 ]
0 commit comments