Avoid rewrite warning for inline runs

When running pytest inline/inprocess we plugins have already been
imported and re-writen, so avoid the warning.
This commit is contained in:
Floris Bruynooghe 2016-06-23 23:51:02 +02:00
parent a98e3cefc5
commit 944da5b98a
2 changed files with 14 additions and 4 deletions

View File

@ -163,9 +163,9 @@ class AssertionRewritingHook(object):
self.session = session
del session
else:
for marked in self._must_rewrite:
if marked.startswith(name):
return True
toplevel_name = name.split('.', 1)[0]
if toplevel_name in self._must_rewrite:
return True
return False
def mark_rewrite(self, *names):

View File

@ -16,6 +16,7 @@ from _pytest._code import Source
import py
import pytest
from _pytest.main import Session, EXIT_OK
from _pytest.assertion.rewrite import AssertionRewritingHook
def pytest_addoption(parser):
@ -685,8 +686,17 @@ class Testdir:
``pytest.main()`` instance should use.
:return: A :py:class:`HookRecorder` instance.
"""
# When running py.test inline any plugins active in the main
# test process are already imported. So this disables the
# warning which will trigger to say they can no longer be
# re-written, which is fine as they are already re-written.
orig_warn = AssertionRewritingHook._warn_already_imported
def revert():
AssertionRewritingHook._warn_already_imported = orig_warn
self.request.addfinalizer(revert)
AssertionRewritingHook._warn_already_imported = lambda *a: None
rec = []
class Collect:
def pytest_configure(x, config):