diff --git a/_pytest/assertion/rewrite.py b/_pytest/assertion/rewrite.py index 50d8062ae..aa33f1352 100644 --- a/_pytest/assertion/rewrite.py +++ b/_pytest/assertion/rewrite.py @@ -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): diff --git a/_pytest/pytester.py b/_pytest/pytester.py index fc5b3ebd9..7831655d1 100644 --- a/_pytest/pytester.py +++ b/_pytest/pytester.py @@ -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):