Skip to content

Commit a704e05

Browse files
committed
Revert sys.module modification
1 parent 1bebe9e commit a704e05

6 files changed

Lines changed: 11 additions & 22 deletions

File tree

tests/conftest.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -308,11 +308,6 @@ def test_app(make_app, sphinx_test_tempdir, request):
308308

309309
app.cleanup()
310310

311-
# unload SN modules to prevent object leaks between test cases
312-
for key in list(sys.modules.keys()):
313-
if key.startswith("sphinx_needs"):
314-
del sys.modules[key]
315-
316311
# Clean up the srcdir of each Sphinx app after the test function has executed
317312
if request.config.getoption("--sn-build-dir") is None:
318313
shutil.rmtree(parent_path, ignore_errors=True)

tests/test_data.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
import inspect
33
from typing import ForwardRef
44

5+
from sphinx_needs.data import NeedsCoreFields, NeedsInfoType
6+
57

68
def test_consistent():
79
"""
@@ -10,8 +12,6 @@ def test_consistent():
1012
So at least here, we check that they are consistent with each other.
1113
"""
1214
# check fields are consistent
13-
from sphinx_needs.data import NeedsCoreFields, NeedsInfoType
14-
1515
assert set(NeedsCoreFields).issubset(set(NeedsInfoType.__annotations__))
1616

1717
# check field types are consistent with schema

tests/test_global_options.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
from sphinx.util.console import strip_colors
77
from syrupy.filters import props
88

9+
from sphinx_needs.config import NeedsSphinxConfig
10+
911

1012
@pytest.mark.parametrize(
1113
"test_app",
@@ -19,8 +21,6 @@
1921
indirect=True,
2022
)
2123
def test_doc_global_option_old(test_app, snapshot):
22-
from sphinx_needs.config import NeedsSphinxConfig
23-
2424
test_app.build()
2525
warnings = strip_colors(
2626
test_app._warning.getvalue().replace(str(test_app.srcdir) + os.sep, "srcdir/")
@@ -57,8 +57,6 @@ def test_doc_global_option_old(test_app, snapshot):
5757
indirect=True,
5858
)
5959
def test_doc_global_option(test_app, snapshot):
60-
from sphinx_needs.config import NeedsSphinxConfig
61-
6260
test_app.build()
6361
warnings = strip_colors(
6462
test_app._warning.getvalue().replace(str(test_app.srcdir) + os.sep, "srcdir/")

tests/test_needimport.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
from sphinx.util.console import strip_colors
88
from syrupy.filters import props
99

10+
from sphinx_needs.data import SphinxNeedsData
11+
from sphinx_needs.directives.needimport import NeedimportException
12+
from sphinx_needs.needsfile import SphinxNeedsFileException
13+
1014

1115
@pytest.mark.parametrize(
1216
"test_app",
@@ -127,9 +131,6 @@ def test_need_schema_warnings(test_app, snapshot):
127131
)
128132
def test_empty_file_check(test_app):
129133
"""Checks that an empty needs.json throws an exception"""
130-
131-
from sphinx_needs.needsfile import SphinxNeedsFileException
132-
133134
app = test_app
134135

135136
with pytest.raises(SphinxNeedsFileException):
@@ -182,8 +183,6 @@ def test_import_builder(test_app, snapshot):
182183
indirect=True,
183184
)
184185
def test_needimport_needs_json_download(test_app, snapshot):
185-
from sphinx_needs.data import SphinxNeedsData
186-
187186
app = test_app
188187

189188
# Mock requests
@@ -259,8 +258,6 @@ def test_needimport_needs_json_download(test_app, snapshot):
259258
indirect=True,
260259
)
261260
def test_needimport_needs_json_download_negative(test_app):
262-
from sphinx_needs.directives.needimport import NeedimportException
263-
264261
with pytest.raises(NeedimportException) as err:
265262
test_app.build()
266263
assert (

tests/test_open_needs_service.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import pytest
44
import responses
55

6+
from sphinx_needs.services.manager import ServiceManager
7+
68
MOCK_NEEDS = [
79
{
810
"key": "NEP_001",
@@ -69,8 +71,6 @@
6971
indirect=True,
7072
)
7173
def test_ons_service(test_app):
72-
from sphinx_needs.services.manager import ServiceManager
73-
7474
responses.post(
7575
"http://127.0.0.1:9595/auth/jwt/login",
7676
status=200,

tests/test_services/test_service_basics.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from sphinx.application import Sphinx
55

66
from sphinx_needs.services.base import BaseService
7+
from sphinx_needs.services.manager import ServiceManager
78

89

910
class ServiceTest(BaseService):
@@ -58,8 +59,6 @@ def request(self, _options):
5859
indirect=True,
5960
)
6061
def test_service_creation(test_app):
61-
from sphinx_needs.services.manager import ServiceManager
62-
6362
app = test_app
6463
app.build()
6564
assert isinstance(app._needs_services, ServiceManager)

0 commit comments

Comments
 (0)