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

How to correctly run pytest.main() programmatically multiple times? #3143

Closed
numirias opened this Issue Jan 23, 2018 · 2 comments

Comments

Projects
None yet
4 participants
@numirias

numirias commented Jan 23, 2018

If I invoke pytest.main(['test_foo.py']) multiple time from the same running script, it will give the same result, even if test_foo.py changes between the runs. (This was also observed in #793.)

But then what is the correct way to rerun pytest programmatically? Could you point me to an example? Starting it in a subprocess feels quite clunky and also makes it more cumbersome to process the results.

(Also, could we possibly have a note about that behavior in the docs? At least to me, it was somewhat unexpected that I can't run pytest.main() in the same script twice.)

@RonnyPfannschmidt

This comment has been minimized.

Member

RonnyPfannschmidt commented Jan 23, 2018

python modules cache in side the same process and due to this property of python its not advisable to run pytest.main twice from the same process

while there may be exceptions to that rule, in general its more safe to run a new process since python is not safe for code reloading

@nicoddemus

This comment has been minimized.

Member

nicoddemus commented Jan 23, 2018

I agree, we should just add a note to the docs regarding that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment