Comments (4)
Hi Thomas,
I don't have ready access to the Debian BTS, so I'm going to update here.
I don't 100% know what's going on here, but I think it is an issue with traceback2 which we started to exhibit after 55278e0 when we started to depend on it.
https://github.com/testing-cabal/traceback2/blob/master/traceback2/__init__.py#L449 assumes that if an exception has a __cause__
, then the cause has a traceback. Clearly this assumption does not always hold.
__cause__
is normally set when an exception is re-raised using the new Python 3 raise from
syntax. Python 3 correctly takes care of setting __traceback__
on __cause__
.
However, it turns out that Django has special code for setting __cause__
on database exceptions:
As per PEP-3134, a
__cause__
attribute is set with the original
(underlying) database exception, allowing access to any additional
information provided. (Note that this attribute is available under
both Python 2 and Python 3, although PEP-3134 normally only applies
to Python 3.)
(from exceptions.txt, some markup edits)
I would suggest that:
- Django should be a little bit better behaved, and at least set
__cause__.__traceback__
to None - traceback2 should be a bit more tolerant of poorly behaved exceptions, and wrap the access of
__traceback__
in agetattr
Hope this helps,
jml
from testtools.
traceback2 is a rolling backport of Python3's traceback module. Per https://docs.python.org/3/library/exceptions.html - "raise new_exc from original_exc
The expression following from must be an exception or None. It will be set as __cause__
on the raised exception."
The expectation in Python 3 is that __cause__
is either None or a valid exception object - which implies the __traceback__
attribute. The likely thing here is that Django is setting __cause__
(non-standard in Python2) without also setting the exceptions __traceback__
- which it needs to do by hand on Python2 (just as it's setting __cause__
by hand)
from testtools.
For reference I have opened a ticket on the Django side: https://code.djangoproject.com/ticket/25761
It will likely get fixed but it's not a high priority ticket so you might still want to rework the code to not make this assumption... if Django did the mistake, it's quite possible other projects did something similar.
from testtools.
Thanks; the place to do that would be in testing-cabal/traceback2 (which is the python stdlib code for traceback handling with only the necessary adjustments to work on Python2.
from testtools.
Related Issues (20)
- Please make a new release HOT 2
- Deprecate testtools.distutilscmd?
- `TestCase.subTest` does not isolate tests
- βIt is no longer useless β¦β in NEWS
- Release to support Python 3.10 HOT 1
- Update `doc/description.rst`
- trailing newline in str comparison is hard to spot
- Compatibility with Python 3.11
- The testtools documentation on readthedocs is not up to date. HOT 3
- 2.5.0 + master: sphinx warnings `reference target not found`
- 2.5.0 + master (b68af1b0): pytest is failing HOT 18
- Test failures with PyPy3.9 HOT 2
- deprecation warning on Python 3.11: 'cgi' is deprecated and slated for removal in Python 3.13 HOT 1
- testcase.py __eq__ function throwing an error
- AttributeError: module 'email' has no attribute 'message' HOT 1
- `testtools` fails to import with Python 3.12 HOT 4
- Issue a python3.12 release HOT 1
- 2.7.0 sdist is unusable (builds version "0.0.0")
- Missing dependency on fixtures since 2.7.0 HOT 1
- Pytest 8: AttributeError: 'TestExpectedException' object has no attribute 'runTest'. Did you mean: 'subTest'? HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from testtools.