[TIP] getting the result of a test in teardown_method?
holger at merlinux.eu
Tue May 11 02:30:10 PDT 2010
On Sat, May 08, 2010 at 22:52 -0700, Hans Sebastian wrote:
> Hi everyone,
> I hope this is where people do Q&A on py.test. Otherwise please direct me to
> the right place.
Yes, I think so. Both nose and py.test (not sure about unittest2)
also have their own mailing lists but policies are somewhat unclear.
Often questions touch general testing issues and I find it interesting
to see how a specific tools/other people see it.
> I've been using py.test to write test scripts. The tests I write use the
> unittest pattern and failure is detected by raising AssertionError. My
> question is how can I get the result of a test immediately in my
> teardown_method(self, method) or in the pytest_runtest_teardown(item) hook?
Both hooks indeed don't (currently) give access to test outcome info.
> The reason I want to know the result at those points is that I want to have
> different teardown logics based on the test result.
With "test result" you mean if an exception was raised or not, right?
As Robert i am not sure i understand why ... usually test fixtures
are supposed to be somewhat independent from test execution.
In py.test there is actually a way to perform teardown and know about the
test outcome but it probably would be slightly hacky and i'd first like
to understand your pattern. Can you work out an abstract example?
More information about the testing-in-python