question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue
  • 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

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:16 (8 by maintainers)

github_iconTop GitHub Comments

2reactions
bluetechcommented, Apr 24, 2020

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!

0reactions
nicoddemuscommented, Apr 26, 2020

Difference is quite significant on red-green-red cycle with one particular test you are working on.

Ahhh definitely. In that case my previous advice should help, as you stated.

Thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to speedup Pytest startup (which is too slow) on loading ...
Suppose we have installed huge library like SageMath. Let consider trivial test file: from sage.all_cmdline import * # import sage library ...
Read more >
tl;dw: Speedily practical large-scale tests - Ned Batchelder
Disk is really slow, avoid it at all costs. First, profile, guessing is no good. But the Python profiler only shows CPU time,...
Read more >
pytest Documentation - Read the Docs
example to early-load the pytest-cov plugin you can use: ... Fixtures can be requested more than once per test (return values are cached)....
Read more >
Testing for Pythonistas: Nose & Pytest - YouTube
Idiomatic python loathes "just because" classes and excessive boilerplate, but the unittest module would feel at home in Java land. Nose and ...
Read more >
Getting Started With Testing in Python
The one built into the Python standard library is called unittest . In this tutorial, you will be using unittest test cases and...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found