Skip to content

Print warning early in pytest output #13056

Closed Answered by JP-Ellis
JP-Ellis asked this question in Q&A
Discussion options

You must be logged in to vote

The solution ultimately was to use a hook. I can't speak for all hooks, but it would appear that PyTest's stdout and stderr capturing are not yet enabled, thereby making warnings like I have above print to the console.

In my specific case of pytest-xdist, they conveniently expose the hook pytest_xdist_setupnodes which I can inspect to verify whether multiple workers are being used:

conftest.py

def pytest_xdist_setupnodes(
    config: pytest.Config,
    specs: Sequence[execnet.XSpec],
) -> None:
    if len(specs) > 1:
        sys.stderr.write("\n")
        warnings.warn(
            "Running the examples with multiple workers may cause issues. "
            "Consider running the examples w…

Replies: 2 comments 4 replies

Comment options

You must be logged in to vote
4 replies
@JP-Ellis
Comment options

@dongfangtianyu
Comment options

@JP-Ellis
Comment options

@dongfangtianyu
Comment options

Comment options

You must be logged in to vote
0 replies
Answer selected by JP-Ellis
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants