diff options
| author | Takeshi KOMIYA <i.tkomiya@gmail.com> | 2020-12-28 23:21:14 +0900 |
|---|---|---|
| committer | Takeshi KOMIYA <i.tkomiya@gmail.com> | 2020-12-29 00:26:23 +0900 |
| commit | 1a659c6ca7e7697eaee67bf97cb56bb3c471d24d (patch) | |
| tree | 95913decb35e76d63bb19202bd4d6a8617503c1f /sphinx/testing | |
| parent | 476169284d2c1ae36d60fd139d5631afa2eade4c (diff) | |
| download | sphinx-git-1a659c6ca7e7697eaee67bf97cb56bb3c471d24d.tar.gz | |
testing: Add rollback_sysmodules fixture to unload modules after tests
Diffstat (limited to 'sphinx/testing')
| -rw-r--r-- | sphinx/testing/fixtures.py | 12 |
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) |
