pytest-dev / pytest-dev/pytest-xdist

how can I run the entire subprocess in a decorated function?

Open
#551 0 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

hiya -

sqlalchemy guy here. I'm doing this thing with asyncio and greenlets, and to make it run the test suite with this special "asyncio / greenlet" mode, I am doing this:

from _pytest.main import pytest_runtestloop as _pytest_runtestloop
def pytest_runtestloop(session):
    return my_magic_runner(_pytest_runtestloop, session)

where above, the entire function that runs everything is actually invoked from the greenlet library. this is not just a "before / after" hook, the run of the tests and all the setups have to be invoked as greenlets. hence I cannot use hookwrapper / yield here.

It doesn't actually have to be one big wrapper for the whole thing, however. I can also wrap each test individually and all the setup/teardown methods. I can do part of this by using pytest_pyfunc_call for individual tests (there's another pytest plugin that does this, i forgot what it is called), however this does not cover things like setup, teardown, and fixtures, and for all of those , I'm not able to identify a clear way to universally decorate all of those without explicitly decorating them. being able to just instrument the entire "run all the setups, tests, and teardowns" in one function is a lot easier.

So my question is, the above hook is not called inside of subprocesses when I use pytest-xdist, and I can't really figure out how pytest-xdist / execnet etc actually do what they are doing. is there some way to just hook around the entire "main" function that's invoked each time within each subprocess? I am wrapping the function in a greenlet, so it can't just be "before" and "after" hooks, the function itself has to be invoked from greenlet.

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 with the mentioned _pytest.main.pytest_runtestloop and pytest_pyfunc_call entry points, then trace how pytest-xdist and execnet start test execution in subprocesses. The issue names no target files or tests; done would mean identifying a supported entry point that invokes setup, tests, and teardown through the requested greenlet wrapper, or documenting why this is not possible.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
distributed-systems, testing-qa
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.