Skip to content

AssertionError has no attribute '__cause__' #2343

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

Closed
icemac opened this issue Apr 1, 2017 · 7 comments
Closed

AssertionError has no attribute '__cause__' #2343

icemac opened this issue Apr 1, 2017 · 7 comments
Assignees

Comments

@icemac
Copy link

icemac commented Apr 1, 2017

The traceback below happened using Python 2.7.13 the AssertionError was caused by a normal assert statement those assertion was false.

Versions:
plugins: cov-2.4.0, flake8-0.8.1, remove-stale-bytecode-2.1, rerunfailures-2.1.0, sugar-0.8.0
pytest 3.0.7, Python 2.7.13 on Mac OS 10.12

INTERNALERROR> Traceback (most recent call last):
INTERNALERROR>   File ".../eggs/pytest-3.0.7-py2.7.egg/_pytest/main.py", line 98, in wrap_session
INTERNALERROR>     session.exitstatus = doit(config, session) or 0
INTERNALERROR>   File ".../eggs/pytest-3.0.7-py2.7.egg/_pytest/main.py", line 133, in _main
INTERNALERROR>     config.hook.pytest_runtestloop(session=session)
INTERNALERROR>   File ".../eggs/pytest-3.0.7-py2.7.egg/_pytest/vendored_packages/pluggy.py", line 745, in __call__
INTERNALERROR>     return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
INTERNALERROR>   File ".../eggs/pytest-3.0.7-py2.7.egg/_pytest/vendored_packages/pluggy.py", line 339, in _hookexec
INTERNALERROR>     return self._inner_hookexec(hook, methods, kwargs)
INTERNALERROR>   File ".../eggs/pytest-3.0.7-py2.7.egg/_pytest/vendored_packages/pluggy.py", line 334, in <lambda>
INTERNALERROR>     _MultiCall(methods, kwargs, hook.spec_opts).execute()
INTERNALERROR>   File ".../eggs/pytest-3.0.7-py2.7.egg/_pytest/vendored_packages/pluggy.py", line 613, in execute
INTERNALERROR>     return _wrapped_call(hook_impl.function(*args), self.execute)
INTERNALERROR>   File ".../eggs/pytest-3.0.7-py2.7.egg/_pytest/vendored_packages/pluggy.py", line 254, in _wrapped_call
INTERNALERROR>     return call_outcome.get_result()
INTERNALERROR>   File ".../eggs/pytest-3.0.7-py2.7.egg/_pytest/vendored_packages/pluggy.py", line 280, in get_result
INTERNALERROR>     _reraise(*ex)  # noqa
INTERNALERROR>   File ".../eggs/pytest-3.0.7-py2.7.egg/_pytest/vendored_packages/pluggy.py", line 265, in __init__
INTERNALERROR>     self.result = func()
INTERNALERROR>   File ".../eggs/pytest-3.0.7-py2.7.egg/_pytest/vendored_packages/pluggy.py", line 614, in execute
INTERNALERROR>     res = hook_impl.function(*args)
INTERNALERROR>   File ".../eggs/pytest-3.0.7-py2.7.egg/_pytest/main.py", line 154, in pytest_runtestloop
INTERNALERROR>     item.config.hook.pytest_runtest_protocol(item=item, nextitem=nextitem)
INTERNALERROR>   File ".../eggs/pytest-3.0.7-py2.7.egg/_pytest/vendored_packages/pluggy.py", line 745, in __call__
INTERNALERROR>     return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
INTERNALERROR>   File ".../eggs/pytest-3.0.7-py2.7.egg/_pytest/vendored_packages/pluggy.py", line 339, in _hookexec
INTERNALERROR>     return self._inner_hookexec(hook, methods, kwargs)
INTERNALERROR>   File ".../eggs/pytest-3.0.7-py2.7.egg/_pytest/vendored_packages/pluggy.py", line 334, in <lambda>
INTERNALERROR>     _MultiCall(methods, kwargs, hook.spec_opts).execute()
INTERNALERROR>   File ".../eggs/pytest-3.0.7-py2.7.egg/_pytest/vendored_packages/pluggy.py", line 613, in execute
INTERNALERROR>     return _wrapped_call(hook_impl.function(*args), self.execute)
INTERNALERROR>   File ".../eggs/pytest-3.0.7-py2.7.egg/_pytest/vendored_packages/pluggy.py", line 254, in _wrapped_call
INTERNALERROR>     return call_outcome.get_result()
INTERNALERROR>   File ".../eggs/pytest-3.0.7-py2.7.egg/_pytest/vendored_packages/pluggy.py", line 280, in get_result
INTERNALERROR>     _reraise(*ex)  # noqa
INTERNALERROR>   File ".../eggs/pytest-3.0.7-py2.7.egg/_pytest/vendored_packages/pluggy.py", line 265, in __init__
INTERNALERROR>     self.result = func()
INTERNALERROR>   File ".../eggs/pytest-3.0.7-py2.7.egg/_pytest/vendored_packages/pluggy.py", line 614, in execute
INTERNALERROR>     res = hook_impl.function(*args)
INTERNALERROR>   File ".../eggs/pytest_rerunfailures-2.1.0-py2.7.egg/pytest_rerunfailures.py", line 75, in pytest_runtest_protocol
INTERNALERROR>     reports = runtestprotocol(item, nextitem=nextitem, log=False)
INTERNALERROR>   File ".../eggs/pytest-3.0.7-py2.7.egg/_pytest/runner.py", line 79, in runtestprotocol
INTERNALERROR>     reports.append(call_and_report(item, "call", log))
INTERNALERROR>   File ".../eggs/pytest-3.0.7-py2.7.egg/_pytest/runner.py", line 135, in call_and_report
INTERNALERROR>     report = hook.pytest_runtest_makereport(item=item, call=call)
INTERNALERROR>   File ".../eggs/pytest-3.0.7-py2.7.egg/_pytest/vendored_packages/pluggy.py", line 745, in __call__
INTERNALERROR>     return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
INTERNALERROR>   File ".../eggs/pytest-3.0.7-py2.7.egg/_pytest/vendored_packages/pluggy.py", line 339, in _hookexec
INTERNALERROR>     return self._inner_hookexec(hook, methods, kwargs)
INTERNALERROR>   File ".../eggs/pytest-3.0.7-py2.7.egg/_pytest/vendored_packages/pluggy.py", line 334, in <lambda>
INTERNALERROR>     _MultiCall(methods, kwargs, hook.spec_opts).execute()
INTERNALERROR>   File ".../eggs/pytest-3.0.7-py2.7.egg/_pytest/vendored_packages/pluggy.py", line 613, in execute
INTERNALERROR>     return _wrapped_call(hook_impl.function(*args), self.execute)
INTERNALERROR>   File ".../eggs/pytest-3.0.7-py2.7.egg/_pytest/vendored_packages/pluggy.py", line 250, in _wrapped_call
INTERNALERROR>     wrap_controller.send(call_outcome)
INTERNALERROR>   File ".../eggs/pytest-3.0.7-py2.7.egg/_pytest/skipping.py", line 227, in pytest_runtest_makereport
INTERNALERROR>     rep = outcome.get_result()
INTERNALERROR>   File ".../eggs/pytest-3.0.7-py2.7.egg/_pytest/vendored_packages/pluggy.py", line 280, in get_result
INTERNALERROR>     _reraise(*ex)  # noqa
INTERNALERROR>   File ".../eggs/pytest-3.0.7-py2.7.egg/_pytest/vendored_packages/pluggy.py", line 265, in __init__
INTERNALERROR>     self.result = func()
INTERNALERROR>   File ".../eggs/pytest-3.0.7-py2.7.egg/_pytest/vendored_packages/pluggy.py", line 614, in execute
INTERNALERROR>     res = hook_impl.function(*args)
INTERNALERROR>   File ".../eggs/pytest-3.0.7-py2.7.egg/_pytest/runner.py", line 272, in pytest_runtest_makereport
INTERNALERROR>     longrepr = item.repr_failure(excinfo)
INTERNALERROR>   File ".../eggs/pytest-3.0.7-py2.7.egg/_pytest/python.py", line 600, in repr_failure
INTERNALERROR>     return self._repr_failure_py(excinfo, style=style)
INTERNALERROR>   File ".../eggs/pytest-3.0.7-py2.7.egg/_pytest/python.py", line 593, in _repr_failure_py
INTERNALERROR>     style=style)
INTERNALERROR>   File ".../eggs/pytest-3.0.7-py2.7.egg/_pytest/main.py", line 449, in _repr_failure_py
INTERNALERROR>     style=style, tbfilter=tbfilter)
INTERNALERROR>   File ".../eggs/pytest-3.0.7-py2.7.egg/_pytest/_code/code.py", line 427, in getrepr
INTERNALERROR>     return fmt.repr_excinfo(self)
INTERNALERROR>   File ".../eggs/pytest-3.0.7-py2.7.egg/_pytest/_code/code.py", line 640, in repr_excinfo
INTERNALERROR>     if e.__cause__ is not None:
INTERNALERROR> AttributeError: 'exceptions.AssertionError' object has no attribute '__cause__'
@RonnyPfannschmidt
Copy link
Member

interesting, according to https://github.com/pytest-dev/pytest/blob/master/_pytest/_code/code.py#L620 this should not happen, care to elaborate on your environment?

@nicoddemus nicoddemus added the status: needs information reporter needs to provide more information; can be closed after 2 or more weeks of inactivity label Apr 6, 2017
@icemac
Copy link
Author

icemac commented Apr 7, 2017

@RonnyPfannschmidt In another test I call:

monkeypatch.setattr("sys.version_info", (3, 0, 0, 'final', 0))
assert ...

Where monkeypatch is the py.test monkeypatch fixture.
Could it be that this patch is not torn down correctly?

@RonnyPfannschmidt
Copy link
Member

@icemac at first glance that seems unlikely, but there may be some merit to investigating this in detail,

its also a potential to restructure things, we shouldn't do such decisions at run-time at all

@nicoddemus
Copy link
Member

The simplest fix is to check against _pytest.compat._PY2 instead of sys.version_info in https://github.com/pytest-dev/pytest/blob/master/_pytest/_code/code.py#L620.

This is in line with our general consensus that we should avoid relying on builtins at run-time (same deal with open during assertion rewrite for example).

@nicoddemus
Copy link
Member

@icemac would you care to contribute a PR with that small fix?

@nicoddemus nicoddemus removed the status: needs information reporter needs to provide more information; can be closed after 2 or more weeks of inactivity label Apr 7, 2017
@icemac icemac self-assigned this Apr 11, 2017
@icemac
Copy link
Author

icemac commented Apr 11, 2017

@nicoddemus Okay.

@icemac
Copy link
Author

icemac commented Apr 12, 2017

Fix see #2359.

nicoddemus added a commit that referenced this issue Apr 12, 2017
Fix #2343: Replace version checks by constants.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants