diff options
author | Bruno Oliveira <nicoddemus@gmail.com> | 2016-10-18 22:58:31 -0200 |
---|---|---|
committer | Bruno Oliveira <nicoddemus@gmail.com> | 2016-10-20 21:40:57 -0200 |
commit | 2a2b8cee09a1a6b706423f7655129e17d7e0383d (patch) | |
tree | 6882ed38dfd0e6bf98ac796be194ad7eead45670 /_pytest/assertion | |
parent | 82fb63ca2d3c8b85d8a13038a16bd104cff1ea6e (diff) | |
download | pytest-2a2b8cee09a1a6b706423f7655129e17d7e0383d.tar.gz |
Fix false-positive warnings from assertion rewrite hook
Fix #2005
Diffstat (limited to '_pytest/assertion')
-rw-r--r-- | _pytest/assertion/rewrite.py | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/_pytest/assertion/rewrite.py b/_pytest/assertion/rewrite.py index 80d6ee3ba..6b4c1f483 100644 --- a/_pytest/assertion/rewrite.py +++ b/_pytest/assertion/rewrite.py @@ -51,6 +51,7 @@ class AssertionRewritingHook(object): self.fnpats = config.getini("python_files") self.session = None self.modules = {} + self._rewritten_names = set() self._register_with_pkg_resources() self._must_rewrite = set() @@ -92,6 +93,8 @@ class AssertionRewritingHook(object): if not self._should_rewrite(name, fn_pypath, state): return None + self._rewritten_names.add(name) + # The requested module looks like a test file, so rewrite it. This is # the most magical part of the process: load the source, rewrite the # asserts, and load the rewritten source. We also cache the rewritten @@ -178,7 +181,9 @@ class AssertionRewritingHook(object): """ already_imported = set(names).intersection(set(sys.modules)) if already_imported: - self._warn_already_imported(already_imported) + for name in names: + if name not in self._rewritten_names: + self._warn_already_imported(already_imported) self._must_rewrite.update(names) def _warn_already_imported(self, names): |