Skip to content

Commit 863c9dc

Browse files
committed
#13 fix regression from mangling sys.modules
1 parent be2a408 commit 863c9dc

File tree

3 files changed

+9
-9
lines changed

3 files changed

+9
-9
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# Changelog
22

33
## [Unreleased]
4+
## Fixed
5+
- Fix #13 regression caused by mangling `sys.modules`
46

57
## [1.0.2] - 2021-03-10
68
### Fixed

pylint_pytest/checkers/fixture.py

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -72,25 +72,20 @@ def visit_module(self, node):
7272
# run pytest session with customized plugin to collect fixtures
7373
fixture_collector = FixtureCollector()
7474

75-
# save and remove modules imported by pytest to prevent pytest warning during fixture collection:
76-
# <PytestAssertRewriteWarning: Module already imported so cannot be rewritten>
77-
sys_mods = set(sys.modules.keys())
78-
7975
# save and restore sys.path to prevent pytest.main from altering it
8076
sys_path = sys.path.copy()
8177

8278
pytest.main(
83-
[node.file, '--fixtures', '--collect-only'],
79+
[
80+
node.file, '--fixtures', '--collect-only',
81+
'--pythonwarnings=ignore:Module already imported:pytest.PytestWarning',
82+
],
8483
plugins=[fixture_collector],
8584
)
8685

8786
# restore sys.path
8887
sys.path = sys_path
8988

90-
# unload modules imported by pytest.main
91-
for module in set(sys.modules.keys()) - sys_mods:
92-
del sys.modules[module]
93-
9489
FixtureChecker._pytest_fixtures = fixture_collector.fixtures
9590
finally:
9691
# restore output devices

tests/base_tester.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import sys
22
import os
3+
from pprint import pprint
4+
35
import astroid
46
from pylint.testutils import UnittestLinter
57
try:
@@ -45,6 +47,7 @@ def verify_messages(self, msg_count, msg_id=None):
4547
if message.msg_id == msg_id:
4648
matched_count += 1
4749

50+
pprint(self.MESSAGES)
4851
assert matched_count == msg_count, f'expecting {msg_count}, actual {matched_count}'
4952

5053
def setup_method(self):

0 commit comments

Comments
 (0)