From 65be1231b12367de3ff14b5718125d12a54b26b1 Mon Sep 17 00:00:00 2001 From: Lev Maximov Date: Sun, 18 Sep 2016 22:34:48 +0700 Subject: [PATCH 1/3] AttributeError chaining bug #1944 fix --- _pytest/python.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/_pytest/python.py b/_pytest/python.py index 33e7cff66..f26c128ca 100644 --- a/_pytest/python.py +++ b/_pytest/python.py @@ -205,11 +205,10 @@ class PyobjContext(object): class PyobjMixin(PyobjContext): def obj(): def fget(self): - try: - return self._obj - except AttributeError: + obj = getattr(self, '_obj', None) + if obj is None: self._obj = obj = self._getobj() - return obj + return obj def fset(self, value): self._obj = value return property(fget, fset, None, "underlying python object") From 6b56c36ae7712cc68b3e7bf2ffd86ba90cde6e0f Mon Sep 17 00:00:00 2001 From: Lev Maximov Date: Sun, 18 Sep 2016 23:14:29 +0700 Subject: [PATCH 2/3] added to changelog and authors --- AUTHORS | 1 + CHANGELOG.rst | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/AUTHORS b/AUTHORS index 636fe7f7b..cce84a3c6 100644 --- a/AUTHORS +++ b/AUTHORS @@ -78,6 +78,7 @@ Kale Kundert Katarzyna Jachim Kevin Cox Lee Kamentsky +Lev Maximov Lukas Bednar Maciek Fijalkowski Maho diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 43bec4fb4..61fb9b5b3 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -12,14 +12,20 @@ * Fix pkg_resources import error in Jython projects (`#1853`). Thanks `@raquel-ucl`_ for the PR. +* Got rid of ``AttributeError: 'Module' object has no attribute '_obj'`` exception + in Python 3 (`#1944`_). + Thanks `@axil`_ for the PR. + * .. _@philpep: https://github.com/philpep .. _@raquel-ucl: https://github.com/raquel-ucl +.. _@axil: https://github.com/axil .. _#1905: https://github.com/pytest-dev/pytest/issues/1905 .. _#1934: https://github.com/pytest-dev/pytest/issues/1934 +.. _#1944: https://github.com/pytest-dev/pytest/issues/1944 3.0.2 From 8cba033bbb16b73726249da8723a9ffec9024ecc Mon Sep 17 00:00:00 2001 From: Lev Maximov Date: Tue, 20 Sep 2016 02:16:04 +0700 Subject: [PATCH 3/3] added a test --- testing/test_assertion.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/testing/test_assertion.py b/testing/test_assertion.py index af7e7e0fe..2d4761431 100644 --- a/testing/test_assertion.py +++ b/testing/test_assertion.py @@ -864,3 +864,15 @@ def test_assert_with_unicode(monkeypatch, testdir): """) result = testdir.runpytest() result.stdout.fnmatch_lines(['*AssertionError*']) + +def test_issue_1944(testdir): + testdir.makepyfile(""" + def f(): + return + + assert f() == 10 + """) + result = testdir.runpytest() + result.stdout.fnmatch_lines(["*1 error*"]) + assert "AttributeError: 'Module' object has no attribute '_obj'" not in result.stdout.str() +