pytest-dev / pytest-dev/pytest-xdist

Unable to filter Warning raised from another pytest plugin with xdist

Open
#758 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Python
Stars
1.9k
Forks
287
Avg merge
9h 30m
Merged PRs (30d)
2

Description

I do have a local pytest plugin that causes some runtime warnings from another dependency.

As these were not a reason to concern, we used filterwarning inside pytest.ini in order to catch and remove them when running tests. The problem is that when run with xdist the filtering no longer happens and we endup with one warning for each CPU.

I think that this happens because the import causing the warnings is happening inside a pytest plugin and before pytest-cov is even loaded but I was not able to find any way to prevent it from happening.

Run with xdist

<frozen importlib._bootstrap>:914: ImportWarning: _AnsibleCollectionFinder.find_spec() not found; falling back to find_module()
=========================================================== test session starts ============================================================
platform darwin -- Python 3.10.0, pytest-6.2.5, py-1.10.0, pluggy-1.0.0
rootdir: /Users/ssbarnea/c/a/ansible-lint, configfile: pytest.ini
plugins: markdown-1.0.2, flaky-3.7.0, mock-3.6.1, xdist-2.4.0, plus-0.2, forked-1.3.0, cov-3.0.0
gw0 C / gw1 C / gw2 C / gw3 C / gw4 C / gw5 C / gw6 C / gw7 C<frozen importlib._bootstrap>:914: ImportWarning: _AnsibleCollectionFinder.find_spec() not found; falling back to find_module()
gw0 ok / gw1 C / gw2 C / gw3 C / gw4 C / gw5 C / gw6 C / gw7 C<frozen importlib._bootstrap>:914: ImportWarning: _AnsibleCollectionFinder.find_spec() not found; falling back to find_module()
gw0 ok / gw1 ok / gw2 C / gw3 C / gw4 C / gw5 C / gw6 C / gw7 C<frozen importlib._bootstrap>:914: ImportWarning: _AnsibleCollectionFinder.find_spec() not found; falling back to find_module()
gw0 ok / gw1 ok / gw2 ok / gw3 C / gw4 C / gw5 C / gw6 C / gw7 C<frozen importlib._bootstrap>:914: ImportWarning: _AnsibleCollectionFinder.find_spec() not found; falling back to find_module()
gw0 ok / gw1 ok / gw2 ok / gw3 ok / gw4 C / gw5 C / gw6 C / gw7 C<frozen importlib._bootstrap>:914: ImportWarning: _AnsibleCollectionFinder.find_spec() not found; falling back to find_module()
gw0 ok / gw1 ok / gw2 ok / gw3 ok / gw4 ok / gw5 C / gw6 C / gw7 C<frozen importlib._bootstrap>:914: ImportWarning: _AnsibleCollectionFinder.find_spec() not found; falling back to find_module()
gw0 ok / gw1 ok / gw2 ok / gw3 ok / gw4 ok / gw5 ok / gw6 C / gw7 C<frozen importlib._bootstrap>:914: ImportWarning: _AnsibleCollectionFinder.find_spec() not found; falling back to find_module()
gw0 ok / gw1 ok / gw2 ok / gw3 ok / gw4 ok / gw5 ok / gw6 ok / gw7 C<frozen importlib._bootstrap>:914: ImportWarning: _AnsibleCollectionFinder.find_spec() not found; falling back to find_module()
gw0 [1] / gw1 [1] / gw2 [1] / gw3 [1] / gw4 [1] / gw5 [1] / gw6 [1] / gw7 [1]
.                                                                                                                                    [100%]
-------------------------- generated xml file: /Users/ssbarnea/c/a/ansible-lint/.test-results/pytest/results.xml ---------------------------
=========================================================== slowest 10 durations ===========================================================

(3 durations < 0.005s hidden.  Use -vv to show these durations.)
============================================================ 1 passed in 8.52s =============================================================
pytest -k test_unjinja  48.61s user 4.44s system 449% cpu 11.793 total

Run with xdist disabled

$ pytest -n0 -k test_unjinja
<frozen importlib._bootstrap>:914: ImportWarning: _AnsibleCollectionFinder.find_spec() not found; falling back to find_module()
=========================================================== test session starts ============================================================
platform darwin -- Python 3.10.0, pytest-6.2.5, py-1.10.0, pluggy-1.0.0
rootdir: /Users/ssbarnea/c/a/ansible-lint, configfile: pytest.ini
plugins: markdown-1.0.2, flaky-3.7.0, mock-3.6.1, xdist-2.4.0, plus-0.2, forked-1.3.0, cov-3.0.0
collected 415 items / 414 deselected / 1 selected
run-last-failure: no previously failed tests, not deselecting items.

test/TestAnsibleLintRule.py .                                                                                                        [100%]

-------------------------- generated xml file: /Users/ssbarnea/c/a/ansible-lint/.test-results/pytest/results.xml ---------------------------
=========================================================== slowest 10 durations ===========================================================

(3 durations < 0.005s hidden.  Use -vv to show these durations.)
==================================================== 1 passed, 414 deselected in 1.55s =====================================================

Related: #338

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the warning with pytest -n and compare it with pytest -n0, using the linked conftest.py, pytest.ini, and test/TestAnsibleLintRule.py as the example setup. Start by tracing warning filtering during xdist worker and plugin initialization. Done means the configured warning is filtered consistently when tests run with xdist, without producing one warning per worker.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
devtools, testing-qa
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.