File tree Expand file tree Collapse file tree 2 files changed +29
-0
lines changed
Expand file tree Collapse file tree 2 files changed +29
-0
lines changed Original file line number Diff line number Diff line change @@ -121,6 +121,14 @@ def __init__(self, config):
121121 self .thread_unsafe = {}
122122 self .run_in_parallel = {}
123123
124+ self .gil_initially_disabled = self ._is_gil_enabled ()
125+
126+ @staticmethod
127+ def _is_gil_enabled ():
128+ if hasattr (sys , "_is_gil_enabled" ):
129+ return sys ._is_gil_enabled ()
130+ return True
131+
124132 def skipped_or_not_parallel (self , * , plural ):
125133 if plural :
126134 skipped = "were skipped"
@@ -286,6 +294,7 @@ def pytest_warning_recorded(
286294 if mo is None or self .ignore_gil_enabled :
287295 return
288296
297+ assert self .gil_initially_disabled and self ._is_gil_enabled ()
289298 if when == "collect" :
290299 stage = "collection"
291300 elif when == "runtest" :
Original file line number Diff line number Diff line change @@ -646,6 +646,16 @@ def test_uses_hypothesis(a, num_parallel_threads):
646646
647647def test_fail_warning_gil_enabled_during_execution (pytester ):
648648 test_name = "test_fail_warning_gil_enabled_during_execution"
649+ pytester .makeconftest ("""
650+ import sys
651+ import pytest
652+
653+ @pytest.hookimpl
654+ def pytest_sessionstart(session):
655+ if not hasattr(sys, "_is_gil_enabled"):
656+ sys._is_gil_enabled = lambda: True
657+ """ )
658+
649659 pytester .makepyfile (f"""
650660 import warnings
651661
@@ -666,6 +676,16 @@ def {test_name}():
666676
667677def test_fail_warning_gil_enabled_during_collection (pytester ):
668678 test_name = "test_fail_warning_gil_enabled_during_collection"
679+ pytester .makeconftest ("""
680+ import sys
681+ import pytest
682+
683+ @pytest.hookimpl
684+ def pytest_sessionstart(session):
685+ if not hasattr(sys, "_is_gil_enabled"):
686+ sys._is_gil_enabled = lambda: True
687+ """ )
688+
669689 pytester .makepyfile (f"""
670690 import warnings
671691 warnings.warn(
You can’t perform that action at this time.
0 commit comments