I'm on the latest pytest version with python 2.7.
In my example my setUp takes 1 second and I would expect the duration report to show that setup took 1 second per test while the calls to the test methods themselves took 0.00, but it is the other way round.
Is this intentionally?
from unittest import TestCase
from time import sleep
class FooTestCase(TestCase):
def setUp(self):
super(FooTestCase, self).setUp()
sleep(1)
def test_foo1(self):
pass
def test_foo2(self):
pass
def test_foo3(self):
pass
=================== test session starts =====================================
platform linux2 -- Python 2.7.6, pytest-4.6.4, py-1.8.0, pluggy-0.12.0 -- /var/venv-stable/bin/python
cachedir: .pytest_cache
Django settings: settings.base (from environment variable)
rootdir: /var/www/foo, inifile: pytest.ini
plugins: django-3.5.1, pudb-0.7.0, super-check-1.0.0
...
============= slowest test durations ==============
1.00s call test_foo.py::FooTestCase::test_foo3
1.00s call test_foo.py::FooTestCase::test_foo1
1.00s call test_foo.py::FooTestCase::test_foo2
0.00s setup test_foo.py::FooTestCase::test_foo1
0.00s teardown test_foo.py::FooTestCase::test_foo3
0.00s setup test_foo.py::FooTestCase::test_foo3
0.00s setup test_foo.py::FooTestCase::test_foo2
0.00s teardown test_foo.py::FooTestCase::test_foo2
0.00s teardown test_foo.py::FooTestCase::test_foo1
============ 3 passed in 3.07 seconds =============
This appears to be specific to unittest:
import pytest
from time import sleep
@pytest.fixture
def setUp():
sleep(1)
class Test:
def test_foo1(self, setUp):
pass
def test_foo2(self, setUp):
pass
def test_foo3(self, setUp):
pass
1.00s setup t_duration.py::Test::test_foo1
1.00s setup t_duration.py::Test::test_foo3
1.00s setup t_duration.py::Test::test_foo2
0.00s call t_duration.py::Test::test_foo3
0.00s teardown t_duration.py::Test::test_foo3
0.00s call t_duration.py::Test::test_foo2
0.00s teardown t_duration.py::Test::test_foo2
0.00s teardown t_duration.py::Test::test_foo1
0.00s call t_duration.py::Test::test_foo1
(tested with 5.0.2.dev72+g4abf95ba4)
Hi,
Indeed it is unittest-specific.
We use unittest's own runner to execute the tests, so the runner itself calls setUp for us.
Unfortunately I don't think there's much we can do on pytest's side, for this reason I'm closing this for now. @belugame feel free to ask further questions. 馃憤
If this cannot be fixed/improved, it might make sense to rather have a single section ("unittest" maybe even) for times then there.
Most helpful comment
This appears to be specific to unittest:
(tested with 5.0.2.dev72+g4abf95ba4)