Skip to content

Commit 944da5b

Browse files
committed
Avoid rewrite warning for inline runs
When running pytest inline/inprocess we plugins have already been imported and re-writen, so avoid the warning.
1 parent a98e3ce commit 944da5b

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

_pytest/assertion/rewrite.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,9 +163,9 @@ def _should_rewrite(self, name, fn_pypath, state):
163163
self.session = session
164164
del session
165165
else:
166-
for marked in self._must_rewrite:
167-
if marked.startswith(name):
168-
return True
166+
toplevel_name = name.split('.', 1)[0]
167+
if toplevel_name in self._must_rewrite:
168+
return True
169169
return False
170170

171171
def mark_rewrite(self, *names):

_pytest/pytester.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import py
1717
import pytest
1818
from _pytest.main import Session, EXIT_OK
19+
from _pytest.assertion.rewrite import AssertionRewritingHook
1920

2021

2122
def pytest_addoption(parser):
@@ -685,8 +686,17 @@ def inline_run(self, *args, **kwargs):
685686
``pytest.main()`` instance should use.
686687
687688
:return: A :py:class:`HookRecorder` instance.
688-
689689
"""
690+
# When running py.test inline any plugins active in the main
691+
# test process are already imported. So this disables the
692+
# warning which will trigger to say they can no longer be
693+
# re-written, which is fine as they are already re-written.
694+
orig_warn = AssertionRewritingHook._warn_already_imported
695+
def revert():
696+
AssertionRewritingHook._warn_already_imported = orig_warn
697+
self.request.addfinalizer(revert)
698+
AssertionRewritingHook._warn_already_imported = lambda *a: None
699+
690700
rec = []
691701
class Collect:
692702
def pytest_configure(x, config):

0 commit comments

Comments
 (0)