File tree 4 files changed +21
-7
lines changed 4 files changed +21
-7
lines changed Original file line number Diff line number Diff line change @@ -179,11 +179,13 @@ def mark_rewrite(self, *names):
179
179
The named module or package as well as any nested modules will
180
180
be rewritten on import.
181
181
"""
182
- already_imported = set (names ).intersection (set (sys .modules ))
183
- if already_imported :
184
- for name in already_imported :
185
- if name not in self ._rewritten_names :
186
- self ._warn_already_imported (name )
182
+ already_imported = (set (names )
183
+ .intersection (sys .modules )
184
+ .difference (self ._rewritten_names ))
185
+ for name in already_imported :
186
+ if not AssertionRewriter .is_rewrite_disabled (
187
+ sys .modules [name ].__doc__ or "" ):
188
+ self ._warn_already_imported (name )
187
189
self ._must_rewrite .update (names )
188
190
189
191
def _warn_already_imported (self , name ):
@@ -635,7 +637,8 @@ def run(self, mod):
635
637
not isinstance (field , ast .expr )):
636
638
nodes .append (field )
637
639
638
- def is_rewrite_disabled (self , docstring ):
640
+ @staticmethod
641
+ def is_rewrite_disabled (docstring ):
639
642
return "PYTEST_DONT_REWRITE" in docstring
640
643
641
644
def variable (self ):
Original file line number Diff line number Diff line change @@ -347,7 +347,7 @@ class RunResult:
347
347
:stdout: :py:class:`LineMatcher` of stdout, use ``stdout.str()`` to
348
348
reconstruct stdout or the commonly used ``stdout.fnmatch_lines()``
349
349
method
350
- :stderrr : :py:class:`LineMatcher` of stderr
350
+ :stderr : :py:class:`LineMatcher` of stderr
351
351
:duration: duration in seconds
352
352
353
353
"""
Original file line number Diff line number Diff line change
1
+ ``PYTEST_DONT_REWRITE`` is now checked for plugins too rather than only for test modules.
Original file line number Diff line number Diff line change @@ -128,6 +128,16 @@ def test_dont_rewrite(self):
128
128
assert len (m .body ) == 1
129
129
assert m .body [0 ].msg is None
130
130
131
+ def test_dont_rewrite_plugin (self , testdir ):
132
+ contents = {
133
+ "conftest.py" : "pytest_plugins = 'plugin'; import plugin" ,
134
+ "plugin.py" : "'PYTEST_DONT_REWRITE'" ,
135
+ "test_foo.py" : "def test_foo(): pass" ,
136
+ }
137
+ testdir .makepyfile (** contents )
138
+ result = testdir .runpytest_subprocess ()
139
+ assert "warnings" not in "" .join (result .outlines )
140
+
131
141
def test_name (self ):
132
142
def f ():
133
143
assert False
You can’t perform that action at this time.
0 commit comments