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

Fixed an issue with running the same test multiple times sequentially #1091

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

yuvalino
Copy link

@yuvalino yuvalino commented May 31, 2024

When pytest_runtest_protocol is called with item==nextitem multiple times, with a test that accepts some fixtures -> the second call forward raises an error.

This is caused in WorkerInteractor when the same test appears twice in a row in the queue.

So if this specific case occurs, ensure nextitem is called with None instead.

yuvalino and others added 2 commits May 31, 2024 23:26
When pytest_runtest_protocol is called with item==nextitem multiple times, with a test that accepts some fixtures -> the second call forward raises an error.

This is caused in WorkerInteractor when the same test appears twice in a row in the queue.

So if this specific case occurs, ensure nextitem is called with None instead.
@bluetech
Copy link
Member

When pytest_runtest_protocol is called with item==nextitem multiple times

I am assuming you are using a plugin which does this. Which plugin is it?

@yuvalino
Copy link
Author

yuvalino commented Jun 1, 2024

pytest-xstress

This is a custom xdist scheduler I'm working on.

I've wrote a workaround for now:
yuvalino/pytest-xstress@e74be4d#diff-174fb39bb2968a8f78ff7ba54c6600843d794c9683efe83987b4291b6ab4db2c

@nicoddemus
Copy link
Member

Thanks @yuvalino however we also will need a regression test for your change for this to be considered for merging.

@amezin
Copy link
Collaborator

amezin commented Jun 4, 2024

the second call forward raises an error.

But what's the error exactly? Is it raised by xdist or pytest core?

nextitem=None will tear down all fixtures (including session scope), if I'm not mistaken. And some code (especially in other plugins) likely assumes nextitem=None means "end of session".

@yuvalino
Copy link
Author

yuvalino commented Jun 9, 2024

@amezin exception is raised by the pytest core, the fixtures are not passed to the "nextitem", so the invocation of the second runtest_protocol fails.

@nicoddemus please explain better what do you mean? as far as I'm aware, no scenario where the same (which is not the case in pytest-repeat) item is executed twice in a row over xdist so there's no regression there, nor in any other use-case of xdist.

I've finished my work by developing multiple plugins (pytest-publish, pytest-xstress) and have come with a final, new vision for tests:

https://github.com/yuvalino/pytest-infinity

infinity

Please help me get this fix out to mainline xdist :)

@amezin
Copy link
Collaborator

amezin commented Jun 9, 2024

@amezin exception is raised by the pytest core, the fixtures are not passed to the "nextitem", so the invocation of the second runtest_protocol fails.

Shouldn't the fix be implemented in pytest core then?

Also, could you show the exact error - message, stack trace?

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

Successfully merging this pull request may close these issues.

4 participants