Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AttributeError chaining bug #1944 fix #1945

Merged
merged 3 commits into from
Sep 20, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ Kale Kundert
Katarzyna Jachim
Kevin Cox
Lee Kamentsky
Lev Maximov
Lukas Bednar
Maciek Fijalkowski
Maho
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 3 additions & 4 deletions _pytest/python.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
12 changes: 12 additions & 0 deletions testing/test_assertion.py
Original file line number Diff line number Diff line change
Expand Up @@ -864,3 +864,15 @@ def test_unicode():
""")
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()