-
Notifications
You must be signed in to change notification settings - Fork 3
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
Make function-scope fixtures run in the same thread as the test function itself #17
Comments
I bumped into pytest-parallel that has been archived and is no longer maintained (latest release in October 2021 and see kevlened/pytest-parallel#104 (comment)), but seems to run the fixture and the test function in the same thread. The following command runs fine:
See their plugin code. Full disclosure, I had to edit the plugin code to avoid an self._log = print # py.log.Producer('pytest-parallel') |
As discussed in the linked scikit-learn issue, it's possible to convert such thread-sensitive fixtures to regular function decorators and the problems go away. So we have a workaround. |
Note that the above workaround is not always valid. For instance, the standard @pytest.mark.parametrize("value", range(10))
def test_stuff_in_isolated_folder(value, tmpdir):
subfolder = tmpdir.mkdir("subfoler") # fails with py.error.EEXIST: [File exists]...
# Do test stuff in "subfolder" and "value". |
While import pytest
@pytest.mark.parametrize("value", list("abcd"))
def test_simple(tmp_path, value):
file_path = tmp_path / "file.txt"
assert not file_path.exists()
file_path.write_text(value)
read_value = file_path.read_text()
assert read_value == value
|
Note that this is a different problem than that reported in #19 as |
I wanted to see if the old, unmaintained But it does not work either (most of the time), but it's broken in a different manner:
EDIT: after editing the fixture code to report more info:
This makes no sense, I suspect that |
Currently, pytest fixtures seem to always be executed in the main thread. This prevents initializing thread-local configuration to run a particular test in isolation of concurrently running tests with different thread-local settings.
See the reproducer below:
resulting in:
Would it be possible to execute function-scope fixtures on the same thread as the test function?
Originally discussed in the context of testing scikit-learn in free threading mode: scikit-learn/scikit-learn#30007
The text was updated successfully, but these errors were encountered: