Skip to content

Commit 7660a19

Browse files
authored
Merge pull request #1945 from axil/master
AttributeError chaining bug #1944 fix
2 parents 8639bf7 + 8cba033 commit 7660a19

File tree

4 files changed

+22
-4
lines changed

4 files changed

+22
-4
lines changed

AUTHORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ Kale Kundert
7878
Katarzyna Jachim
7979
Kevin Cox
8080
Lee Kamentsky
81+
Lev Maximov
8182
Lukas Bednar
8283
Maciek Fijalkowski
8384
Maho

CHANGELOG.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,20 @@
1212
* Fix pkg_resources import error in Jython projects (`#1853`).
1313
Thanks `@raquel-ucl`_ for the PR.
1414

15+
* Got rid of ``AttributeError: 'Module' object has no attribute '_obj'`` exception
16+
in Python 3 (`#1944`_).
17+
Thanks `@axil`_ for the PR.
18+
1519
*
1620

1721

1822
.. _@philpep: https://github.com/philpep
1923
.. _@raquel-ucl: https://github.com/raquel-ucl
24+
.. _@axil: https://github.com/axil
2025

2126
.. _#1905: https://github.com/pytest-dev/pytest/issues/1905
2227
.. _#1934: https://github.com/pytest-dev/pytest/issues/1934
28+
.. _#1944: https://github.com/pytest-dev/pytest/issues/1944
2329

2430

2531
3.0.2

_pytest/python.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -205,11 +205,10 @@ class PyobjContext(object):
205205
class PyobjMixin(PyobjContext):
206206
def obj():
207207
def fget(self):
208-
try:
209-
return self._obj
210-
except AttributeError:
208+
obj = getattr(self, '_obj', None)
209+
if obj is None:
211210
self._obj = obj = self._getobj()
212-
return obj
211+
return obj
213212
def fset(self, value):
214213
self._obj = value
215214
return property(fget, fset, None, "underlying python object")

testing/test_assertion.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -864,3 +864,15 @@ def test_unicode():
864864
""")
865865
result = testdir.runpytest()
866866
result.stdout.fnmatch_lines(['*AssertionError*'])
867+
868+
def test_issue_1944(testdir):
869+
testdir.makepyfile("""
870+
def f():
871+
return
872+
873+
assert f() == 10
874+
""")
875+
result = testdir.runpytest()
876+
result.stdout.fnmatch_lines(["*1 error*"])
877+
assert "AttributeError: 'Module' object has no attribute '_obj'" not in result.stdout.str()
878+

0 commit comments

Comments
 (0)