From 969a6f9d4402982e0ae7f9d3f1a6df0adf9b74e7 Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Sat, 20 Sep 2025 08:44:40 -0300 Subject: [PATCH] Do not import pytest in unittest.py We should not import pytest directly in internal modules, as it might cause circular references because `import pytest` imports many other internal modules. --- src/_pytest/unittest.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/_pytest/unittest.py b/src/_pytest/unittest.py index 341173ee6ac..282f7b25680 100644 --- a/src/_pytest/unittest.py +++ b/src/_pytest/unittest.py @@ -30,7 +30,6 @@ from _pytest.python import Function from _pytest.python import Module from _pytest.runner import CallInfo -import pytest if sys.version_info[:2] < (3, 11): @@ -141,7 +140,7 @@ def unittest_setup_class_fixture( cls = request.cls if _is_skipped(cls): reason = cls.__unittest_skip_why__ - raise pytest.skip.Exception(reason, _use_item_location=True) + raise skip.Exception(reason, _use_item_location=True) if setup is not None: try: setup() @@ -182,7 +181,7 @@ def unittest_setup_method_fixture( self = request.instance if _is_skipped(self): reason = self.__unittest_skip_why__ - raise pytest.skip.Exception(reason, _use_item_location=True) + raise skip.Exception(reason, _use_item_location=True) if setup is not None: setup(self, request.function) yield @@ -280,7 +279,7 @@ def addFailure( def addSkip(self, testcase: unittest.TestCase, reason: str) -> None: try: - raise pytest.skip.Exception(reason, _use_item_location=True) + raise skip.Exception(reason, _use_item_location=True) except skip.Exception: self._addexcinfo(sys.exc_info())