Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pytest_sessionfinish hook executes before the last worker is done #1045

Open
k-macmillan opened this issue Mar 19, 2024 · 2 comments
Open

pytest_sessionfinish hook executes before the last worker is done #1045

k-macmillan opened this issue Mar 19, 2024 · 2 comments

Comments

@k-macmillan
Copy link

pytest_sessionfinish is a built-in pytest hook method that executes after all tests finish.

Called after whole test run finished, right before returning the exit status to the system.

pytest-xdist violates the intended usage of the function by calling the method while workers are still running, rather than "right before returning the exit status to the system". It does not run multiple times for each worker, so it appears something internal to pytest-xdist executes this before all workers are done.

If this is a desired outcome it would be beneficial to document it.

@nickmelchiorre
Copy link

I am having a similar issue, I want to access the session data and retrieve the failed tests using this in conftest

def pytest_sessionfinish(session, exitstatus):
        if exitstatus == 1:
            for sess in session.items:
                if sess._test_failed_statuses["call"]:
                    payload["description"] += f"\n- {sess.nodeid}"

But when running with xdist I am getting this error :

 line 162, in pytest_sessionfinish
    for sess in session.items:
AttributeError: 'Session' object has no attribute 'items'

What is the work around to access the session data for all the tests.

@allurelzh
Copy link

我也遇到了这个问题pytest_sessionfinish会被多个worker执行,而不是在整个测试流程结束之后执行一次

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants