Closed
Description
test.py
:
import unittest
class Tests(unittest.TestCase):
def setUp(self):
print 'setUp'
def test_skip(self):
print 'skip'
self.skipTest('skip')
def tearDown(self):
print 'tearDown'
Output without --pdb
:
$ pytest -s test.py
=========================== test session starts ============================
platform darwin -- Python 3.6.8, pytest-5.2.1, py-1.8.0, pluggy-0.12.0
collected 1 item
test.py setUp
skip
tearDown
s
============================ 1 skipped in 0.01s ============================
Output with --pdb
:
$ pytest -s --pdb test.py
=========================== test session starts ============================
platform darwin -- Python 3.6.8, pytest-5.2.1, py-1.8.0, pluggy-0.12.0
collected 1 item
test.py setUp
skip
s
============================ 1 skipped in 0.01s ============================
When --pdb
is not specified, tearDown
is run as expected. With --pdb
, is isn't run. I've mostly tracked this down to exception handling in unittest.TestCase.run()
that will intercept the SkipTest
exception raised by TestCase.skipTest()
and still run tearDown
, but TestCase.debug()
does not handle any exceptions, including SkipTest
, so it will not run tearDown
. This could be argued to be an upstream bug in unittest
itself, but I'm not even sure if TestCase.debug()
is actually the intended mechanism to be used for this scenario.
This basically means that after skipped tests there's no way to tear down stuff that has been set up in setUp
when running with --pdb
.
pip list
:
Package Version
------------------ -------
atomicwrites 1.3.0
attrs 19.3.0
importlib-metadata 0.23
more-itertools 7.2.0
packaging 19.2
pip 19.3.1
pluggy 0.13.0
py 1.8.0
pyparsing 2.4.2
pytest 5.2.1
setuptools 41.4.0
six 1.12.0
wcwidth 0.1.7
wheel 0.33.6
zipp 0.6.0