Skip to content

Use pytest tmp file management fixtures instead of ensure_clean[_path|_dir] #26984

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

Closed
jgehrcke opened this issue Jun 21, 2019 · 6 comments
Closed
Labels
Enhancement IO Data IO issues that don't fit into a more specific label Testing pandas testing functions or related to the test suite

Comments

@jgehrcke
Copy link
Contributor

jgehrcke commented Jun 21, 2019

Opened as of discussion in #26818.

tests/io/test_pytables.py uses a context manager called ensure_clean_path. It might be worth using the pytest tmp_path fixture instead which I think provides everything we need with less code (also easier to understand for new contributors familiar with pytest). And it provides even a little more functionality, comparison:

  • it guarantees file system isolation between tests (as does ensure_clean_path).
  • it makes it obvious which file belongs to which test via expressive naming (as opposed to ensure_clean_path).
  • it retains files for later inspection as opposed to ensure_clean_path. That can be useful for debugging after test failure.

Note: the pytest-managed temp files are removed in a rolling fashion across test runner invocations so that storage space requirement does not grow indefinitely with the number of invocations.

Cf. comment #26818 (comment)

@simonjayhawkins simonjayhawkins added Needs Discussion Requires discussion from core team before further action Testing pandas testing functions or related to the test suite labels Jun 21, 2019
@simonjayhawkins
Copy link
Member

I think the issue should address pytest replacements for ensure_clean and ensure_clean_dir functions in pandas.util.testing and not just it's use in tests/io/test_pytables.py

+1 for using pytest fixtures thoughout.

@jgehrcke jgehrcke changed the title test_pytables: use pytest tmp_path fixture instead of ensure_clean_path Use pytest tmp file management fixtures instead of ensure_clean[_path|_dir] Jun 21, 2019
@jreback
Copy link
Contributor

jreback commented Jun 21, 2019

@jgehrcke I am pretty ok with doing this change, does it require a specific version min for pytest?; we should update the docs in contributing.rst (not sure if we have any text about this though)

@simonjayhawkins
Copy link
Member

I am pretty ok with doing this change

probably not all at once? used in many places.

does it require a specific version min for pytest?

we'll probably want to use the newer tmp_path which returns a pathlib.Path (in python < 3.6 this is a pathlib2.Path) instead of the older tmpdir which returns a py.path.local path object.

tmp_path (and tmp_path_factory) were added in pytest 3.9.0

@jreback
Copy link
Contributor

jreback commented Oct 7, 2019

we should do this post dropping 3.5 (I don't know if we have an issue for that yet).

@simonjayhawkins
Copy link
Member

fair enough. dropping py3.5 probably not far away, but probably OK to use when adding new tests/fixtures?

did use tmp_path in filepath_or_buffer fixture in tests\io\formats\test_format.py #27598

@mroeschke mroeschke removed the Clean label Jul 10, 2021
@mroeschke mroeschke added the IO Data IO issues that don't fit into a more specific label label Jul 1, 2022
@mroeschke
Copy link
Member

I think we've cleaned up ensure_clean_path usage as much as much as possible, we still need that method for custom file path handling and file returning so going to close as completed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement IO Data IO issues that don't fit into a more specific label Testing pandas testing functions or related to the test suite
Projects
None yet
Development

No branches or pull requests

4 participants