self._outcome.result is not a unittest.TestResult when subclassing unittest.TestCase on Python 3.11 #10631
Labels
status: help wanted
developers would like help from experts on this topic
type: proposal
proposal for a new feature, often to gather opinions or design the API around the new feature
Uh oh!
There was an error while loading. Please reload this page.
There's a reasonably common idiom to get results from a test that subclass
unittest.TestCase
inside atearDown()
method by accessingself._outcome.errors
(see #7000). In Python 3.11, unittest has changed so thatself._outcome.errors
doesn't exist (the_Outcome
object does not have theerrors
attribute), but a popular workaround suggested on StackOverflow involves accessingself._outcome.result
on Python 3.11 (and later), which is aunittest.TestResult
that has memberserrors
andfailures
(and alsoskipped
) and can be processed in the same way.However, when running tests inside pytest,
self._outcome.result
inside thetearDown()
method is not aunittest.TestResult
, but apytest._unittest.TestCaseFunction
, which means that the above snipped from StackOverflow that works, e.g., with CTest, will produceAttributeErrors
and report test failures:Wireshark uses this idiom for our testing, and while our standard CI/CD tests use CTest (with a
test
target insidecmake
), some developers appreciate being able to run the tests withinpytest
, which worked up until Python 3.11.Installed versions
pytest 7.1.3, Fedora 37, Python 3.11.1
The text was updated successfully, but these errors were encountered: