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

Use pytest tmpdir_factory in gen_cluster #6630

Closed
wants to merge 1 commit into from

Conversation

fjetter
Copy link
Member

@fjetter fjetter commented Jun 24, 2022

Alternative to #6628

This will always infect the tmpdir_factory fixture to gen_cluster and use this for the creation of the tmpdir. If the function itself requires the fixture it will be forwarded to the function, otherwise we'll throw it away.

@fjetter
Copy link
Member Author

fjetter commented Jun 24, 2022

see #6625 (comment)

@graingert
Copy link
Member

graingert commented Jun 24, 2022

tmpdir_factory is the old temporary path tool I think you should use https://docs.pytest.org/en/7.1.x/how-to/tmp_path.html#the-tmp-path-factory-fixture

If you're injecting the fixture via the signature you can use the real tmp_path rather than the factory.

@fjetter fjetter force-pushed the gen_cluster_tmpdir_factory branch from daf2942 to d8c654f Compare June 24, 2022 15:53

@functools.wraps(func)
@clean(**clean_kwargs)
def test_func(*outer_args, **kwargs):
async def async_fn():
result = None
with tempfile.TemporaryDirectory() as tmpdir:
with contextlib.ExitStack() as exitstack:
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm sure there is much more we could do with an exitstack int his function but I'd rather not touch it for now

tmp_path_factory = kwargs.get("tmp_path_factory")
if tmp_path_factory is None:
# For usage as plain ctxmanager for non-pytest functions
tmpdir = str(exitstack.enter_context(_SafeTemporaryDirectory()))
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is unfortunately the case where tests are using this in an inner function w/out pytest-collection, i.e. we need to handle this case as well

@fjetter
Copy link
Member Author

fjetter commented Jun 24, 2022

Particularly with the latest changes to support non-pytest gen_cluster usage, I'm inclined to go with #6628 and see if this resolves our issue already. this turned out to be a bit ugly imo

@graingert
Copy link
Member

I'm also wondering if we have the opposite problem where tmp_path is being kept for the whole test suite and we're running out of disk space?

https://github.com/pytest-dev/pytest/blob/28e8c8582ea947704655a3c3f2d57184831336fd/src/_pytest/tmpdir.py#L148

@fjetter
Copy link
Member Author

fjetter commented Jun 24, 2022

out of disk space?

I think we'd see different exceptions, wouldn't we?

@github-actions
Copy link
Contributor

Unit Test Results

See test report for an extended history of previous test failures. This is useful for diagnosing flaky tests.

       15 files         15 suites   10h 24m 54s ⏱️
  2 892 tests   2 793 ✔️   84 💤   14  1 🔥
21 423 runs  20 339 ✔️ 970 💤 113  1 🔥

For more details on these failures and errors, see this check.

Results for commit d8c654f.

@fjetter
Copy link
Member Author

fjetter commented Jun 27, 2022

closing in favor of #6628

@fjetter fjetter closed this Jun 27, 2022
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.

2 participants