Uh oh!
There was an error while loading. Please reload this page.
chore: Convert direct multiprocessing.set_start_method("forkserver") call to a pytest fixture. - #4377
Conversation
Oh, this looks interesting! (I think it's much more than a chore!) Do you already know if that gets rid of the repeat that popped up under #4376? |
Skylion007
commented
Dec 1, 2022
@rwgk I am not sure? This is just functionally the same as it was before, just prevents the code from being run twice by having it be a pytest.fixture . |
Skylion007
commented
Dec 1, 2022
All the failures are flakes. Happy to merge pending approval. |
rwgk
commented
Dec 1, 2022
Please give me a moment to try if it helps getting rid of the spurious I believe this PR is good even if it doesn't help, but I want to try first, in case a tweak here is needed for something. TBH I don't really understand this sentence:
Did you mean "called once"? I think I'm missing something fundamental about how fixtures work. Could you please help me (and others) understand? My (maybe incorrect) best-guess understanding is: conftest.py is imported only once, when pytest starts up. There is no direct reference to |
Skylion007
commented
Dec 1, 2022
Yep This doc has some really good explanation about the order the fixtures are called and when. a scope='session` is called once when pytest startups and its state is shared among all tests that include it. By adding autouse=True, it is automatically added to all tests affected by conftest.py meaning that it is run regardless of which test is run, and it is only once per session (hence scope="session"). You can also have fixtures run once per module, once per class, etc... to store global state, or to have a piece of code run once before the first instance of the class is created etc... |
Skylion007
commented
Dec 1, 2022
Yeah, true, but let's say you just wanted to import code snippits from it outside of a pytest context for debugging, it would still set the multiprocessing state, which may be undesirable. Fixture are also nice because they document how the state of the program is setup for each test. |
rwgk
commented
Dec 1, 2022
Thanks, I need a moment to look. Quick results:
|
Skylion007
commented
Dec 1, 2022
Yeah, it should be executed once either way, this just make it more robust and it ensures its' not executed more than once by more edge case things like abusing |
rwgk
left a comment
There was a problem hiding this comment.
Could you please work your latest explanations into the PR description before merging?
Even more importantly: update the title? (because that goes into the commit hash)
I don't think "bugfix" is appropriate.
"best practices" seem more fitting.
But I'd just say what this does in the title and carefully explain in the description.
Suggested title:
Convert direct multiprocessing.set_start_method("forkserver") call to a pytest fixture.
Uh oh!
There was an error while loading. Please reload this page.
rwgk
commented
Dec 1, 2022
Nice description! |
Description
multiprocessingstart_method"forkserver"#4306. This should be a bit safer since it ensure it can only be called once and if we import anything from conftest for whatever reason, it won't try to run the code snippit again. This is what we should have done at the start as putting any "raw" code in conftest.py is ill advised and bugprone.importlib.reloador autoreload etc from Jupyter notebooks and better documents what functions are affecting the global state before a test is runSuggested changelog entry: