Skip to content

Commit f99cf2d

Browse files
author
deathaxe
authored
Fix circular import due to DeferrableTestSuite (#262)
This commit moves (duplicates) loader module into py33 and p38 packages and imports it from there to avoid a circular import.
1 parent f917a24 commit f99cf2d

File tree

4 files changed

+20
-7
lines changed

4 files changed

+20
-7
lines changed

unittesting/core/__init__.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,25 @@
44
from .py38.case import DeferrableMethod
55
from .py38.case import DeferrableTestCase
66
from .py38.case import expectedFailure
7+
from .py38.loader import DeferrableTestLoader
78
from .py38.runner import AWAIT_WORKER
89
from .py38.runner import DeferringTextTestRunner
910
from .py38.suite import DeferrableTestSuite
1011
else:
1112
from .py33.case import DeferrableMethod
1213
from .py33.case import DeferrableTestCase
1314
from .py33.case import expectedFailure
15+
from .py33.loader import DeferrableTestLoader
1416
from .py33.runner import AWAIT_WORKER
1517
from .py33.runner import DeferringTextTestRunner
1618
from .py33.suite import DeferrableTestSuite
1719

18-
from .loader import UnitTestingLoader as TestLoader
19-
2020
__all__ = [
2121
"AWAIT_WORKER",
2222
"DeferrableMethod",
2323
"DeferrableTestCase",
24+
"DeferrableTestLoader",
2425
"DeferrableTestSuite",
2526
"DeferringTextTestRunner",
2627
"expectedFailure",
27-
"TestLoader",
2828
]

unittesting/core/loader.py unittesting/core/py33/loader.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
from unittest import TestSuite
22
from unittest import TestLoader
33

4-
from . import DeferrableTestSuite
4+
from .suite import DeferrableTestSuite
55

66

7-
class UnitTestingLoader(TestLoader):
7+
class DeferrableTestLoader(TestLoader):
88
def __init__(self, deferred=False):
99
if deferred:
1010
self.suiteClass = DeferrableTestSuite

unittesting/core/py38/loader.py

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
from unittest import TestSuite
2+
from unittest import TestLoader
3+
4+
from .suite import DeferrableTestSuite
5+
6+
7+
class DeferrableTestLoader(TestLoader):
8+
def __init__(self, deferred=False):
9+
if deferred:
10+
self.suiteClass = DeferrableTestSuite
11+
else:
12+
self.suiteClass = TestSuite
13+
super().__init__()

unittesting/unit.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
from .base import BaseUnittestingCommand
1212
from .base import DONE_MESSAGE
1313
from .core import DeferrableTestCase
14+
from .core import DeferrableTestLoader
1415
from .core import DeferringTextTestRunner
15-
from .core import TestLoader
1616
from .utils import reload_package
1717
from .utils import StdioSplitter
1818

@@ -207,7 +207,7 @@ def run_tests(self, stream, package, settings, cleanup_hooks=[]):
207207
if not is_empty_test:
208208
# use custom loader which supports reloading modules
209209
self.remove_test_modules(package, settings["tests_dir"])
210-
loader = TestLoader(settings["deferred"])
210+
loader = DeferrableTestLoader(settings["deferred"])
211211
if os.path.exists(os.path.join(start_dir, "__init__.py")):
212212
tests = loader.discover(
213213
start_dir, settings["pattern"], top_level_dir=package_dir

0 commit comments

Comments
 (0)