pytest-dev / pytest-dev/pytest-xdist

Non-initial conftest.py not run with output capturing.

Open
#4 9 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

I normally run my test suite using the -n <num> option. My setup.cfg was previously set to pass a fixed list of paths as arguments to py.test via the addopts setting. I changed setup.cfg to no longer use a fixed list of paths (instead using the python_files glob option) in order to allow paths to be specified normally. After this change, I found that output from the logging module was no longer captured.

The logging module is initialized with basicConfig upon import of a log module inside the application package. This is unavoidable. The log module is indirectly imported by a conftest.py module. This is not unavoidable, just very inconvenient to work around; besides, I want to see the log output along with the results of failing tests.

Further investigation yielded some confusing results.

To reproduce the behavior, I created a test suite structured like this:

tests/
  foo/
    conftest.py
    test_foo.py
 bar/
    test_bar.py

No setup.cfg or similar is present.

foo/conftest.py initializes the logging module using basicConfig. Both foo/test_foo.py and bar/test_bar.py contain a test function that calls the logging module to log a single message, "Hello World". Under certain conditions, the "Hello World" message is not captured for any test, but sent to stderr instead. I have narrowed down those conditions to these invocations of py.test with capturing results:

  • py.test without -n <num>, regardless of other arguments: Captured
  • py.test -n 3 without other arguments: Not captured
  • py.test -n 3 tests: Not captured
  • py.test -n 3 tests/foo: Captured
  • py.test -n 3 tests/foo/test_foo.py: Captured
  • py.test -n 3 tests/bar: Captured
  • py.test -n 3 tests/bar/test_bar.py: Captured

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

Start by reproducing the listed invocations with the tests/foo/conftest.py fixture and compare logging capture for tests/foo and tests/bar. Read the pytest-xdist handling around distributed test collection and output capture. Done means logging from both tests is captured consistently when running the suite with -n 3.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
testing-qa
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.