Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/sphinx-doc/sphinx.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTakeshi KOMIYA <i.tkomiya@gmail.com>2020-12-28 17:21:14 +0300
committerTakeshi KOMIYA <i.tkomiya@gmail.com>2020-12-28 18:26:23 +0300
commit1a659c6ca7e7697eaee67bf97cb56bb3c471d24d (patch)
tree95913decb35e76d63bb19202bd4d6a8617503c1f /sphinx/testing
parent476169284d2c1ae36d60fd139d5631afa2eade4c (diff)
testing: Add rollback_sysmodules fixture to unload modules after tests
Diffstat (limited to 'sphinx/testing')
-rw-r--r--sphinx/testing/fixtures.py12
1 files changed, 12 insertions, 0 deletions
diff --git a/sphinx/testing/fixtures.py b/sphinx/testing/fixtures.py
index e6c3edd18..b9ee30d8a 100644
--- a/sphinx/testing/fixtures.py
+++ b/sphinx/testing/fixtures.py
@@ -250,3 +250,15 @@ def tempdir(tmpdir: str) -> "util.path":
this fixture is for compat with old test implementation.
"""
return util.path(tmpdir)
+
+
+@pytest.fixture
+def rollback_sysmodules():
+ """Rollback sys.modules to before testing to unload modules during tests."""
+ try:
+ sysmodules = list(sys.modules)
+ yield
+ finally:
+ for modname in list(sys.modules):
+ if modname not in sysmodules:
+ sys.modules.pop(modname)