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 5.3.3: slow or crashing tests

See original GitHub issue

tl;dr: If your tests are slow or break on pytest 5.3.3, please pin pytest==5.3.2 until this is resolved. A change to fixture handling seems incompatible with at least pytest-django, but also some non-Django projects.

A change in 99180939febb6ca4b3ff788cf336b065046653f2 (part of the 5.3.3 release) led to an incompatibility regarding fixture handling/cleanup. It seems fixtures are not correctly recycled/collected, so they persist in unintended ways.

Original report with plenty of unimportant details inside:

I'm testing a Django project with pytest, pytest-xdist, pytest-django, and tox as runner. As of the latest pytest release ~2 hours ago, 5.3.3, I'm seeing the weirdest test failures.

The errors can be seen here:

django.core.exceptions.ImproperlyConfigured: The database name 'test_travis_ci_test_gw0_gw0_gw0_gw0_gw0_gw0_gw0_gw0_gw0_gw0_gw0_gw0_gw0' (71 characters) is longer than PostgreSQL's limit of 63 characters. Supply a shorter NAME in settings.DATABASES.
---------------------------- Captured stderr setup -----------------------------
Got an error creating the test database: database "test_travis_ci_test_gw0_gw0_gw0_gw0_gw0_gw0_gw0_gw0_gw0_gw0_gw0" already exists

or using MySQL:

---------------------------------------------------------------------------------------------- Captured stderr setup ----------------------------------------------------------------------------------------------
Got an error creating the test database: (1102, "Incorrect database name 'test_pretalx_gw7_gw7_gw7_gw7_gw7_gw7_gw7_gw7_gw7_gw7_gw7_gw7_gw7_gw7_gw7_gw7_gw7_gw7_gw7_gw7_gw7_gw7'")

The database name is supposedly generated by pytest-xdist, which is running on gw0 and gw1 in this Travis runner.

From my local debugging: It appears that initally, pytest-xdist will create databases called “test_pretalx_gw0” and so on, but then I see those disappear and be replaced by “test_pretalx_gw0_gw0”, then “test_pretalx_gw0_gw0_gw0”, and so on, while the tests are running. They aren’t all replaced at the same time, and not for each test, but (I think) each time each thread opens a new module/test file.

I’m not sure if the fault rests with pytest, or pytest-xdist, or pytest-django, but it’s only present as of the 5.3.3. bugfix release, with 5.3.2 running as intended (and significantly faster, at that). I’m reporting this here in hopes of help, and because while the error implies that the problem lies with either pytest-xdist or pytest-django, the change was definitely introduced on the side of pytest itself.

I’m happy to provide more details or debugging.

</detail>

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:4
  • Comments:46 (30 by maintainers)

github_iconTop GitHub Comments

1reaction
mvbrncommented, Jan 17, 2020

@blueyed pytest-django is present 😃

upd: downgrade to pytest==5.3.2 helped me

1reaction
nicoddemuscommented, Jan 17, 2020

Thanks @rixx.

That confirms my suspicion that it is related to #6438.

The fix might have caused a regression in pytest-django though, so I suggest to cross-post this in https://github.com/pytest-dev/pytest-django/issues. 👍

Read more comments on GitHub >

github_iconTop Results From Across the Web

Flaky tests — pytest documentation
A “flaky” test is one that exhibits intermittent or sporadic failure, that seems to have non-deterministic behaviour. Sometimes it passes, sometimes it ...
Read more >
pytest - PyPI
The pytest framework makes it easy to write small tests, yet scales to support complex functional testing for applications and libraries.
Read more >
What's New - Oracle Linux Yum Server
Oracle Linux with Oracle enterprise-class support is the best Linux operating system (OS) for your enterprise computing needs.
Read more >
Playwright Crash Course with PyTest - YouTube
In this video Andrew shows how you can write tests using Playwight with Pytest. It will get you started with everything you need...
Read more >
Pytest running very slow for project - python - Stack Overflow
Is it still slow when restricting the directory to scan? E.g. pytest --collect-only root/a/tests . Maybe you have some large dir in project...
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