pytest: Pytest more than twice slower than Nosetest on trivial test with huge library to load

  • a detailed description of the bug or suggestion
  • output of pip list from the virtual environment you are using
  • pytest and operating system versions
  • minimal example if possible

Suppose we have installed huge library like SageMath. Let consider trivial test file:

from sage.all_cmdline import *   # import sage library


class TestClass:
        def test_method(self):
                assert True

It runs for about 1.5 sec with Nosetest

$ time nosetests test.py
.
----------------------------------------------------------------------
Ran 1 test in 0.000s

OK
nosetests test.py  1.38s user 0.14s system 97% cpu 1.567 total

Whereas with pytest it runs for ~4.5 sec!

$ time pytest test.py
platform linux -- Python 3.8.2, pytest-5.4.1, py-1.8.1, pluggy-0.13.1
rootdir: /home/user/pytest, inifile: pytest.ini
plugins: profiling-1.7.0
collecting 1 item 

/usr/lib/python3.8/site-packages/sage/misc/sage_unittest.py:20:
PytestCollectionWarning: cannot collect test class 'TestSuite' because it has a __init__ constructor (from: test.py)

  class TestSuite(object):
collected 1 item

test.py .                                                                                                                                               [100%]

====================================================================== 1 passed in 3.26s ======================================================================
pytest test.py  3.86s user 0.46s system 101% cpu 4.253 total

It looks (according to the warning) like pytest collects some tests from the library itself or may be something else.

P.S. Arch linux with latest upgrades.

This is pytest version 5.4.1, imported from /usr/lib/python3.8/site-packages/pytest/__init__.py
setuptools registered plugins:
  pytest-profiling-1.7.0 at /usr/lib/python3.8/site-packages/pytest_profiling.py

Pip list: http://dpaste.com/34FAXBR

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 16 (8 by maintainers)

Most upvoted comments

I don’t think pytest should look into /usr/lib/python3.8/site-packages in this manner, so this is strange.

If you can provide a minimal reproduction (i.e. a fresh venv with just what’s needed installed and a test file, and the commands you run), I’ll take a look. I also use Arch Linux and can install Sagemath if needed, even though IIRC it is was quite massive!