question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Uses of `pytest`'s `tmpdir` fixture should be replaced with `tmp_path`

See original GitHub issue

Description

Some of the tests involve writing data, and such data should not be stored permanently. pytest has two fixtures that provide temporary directories for writing test data: the recommended tmp_path, which uses pathlib.Path from the Python standard library, and the legacy tmpdir utilizing py.path, a third party library. The following shell command reveals that many tests in astropy still use tmpdir:

git grep --files-with-matches tmpdir -- *tests*

All uses of tmpdir should be replaced with tmp_path, although not all sub-packages have to be updated in a single pull request.

Sub-packages to update

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:20 (20 by maintainers)

github_iconTop GitHub Comments

3reactions
pllimcommented, Oct 4, 2022

Yeah, definitely save io.fits for last. Thanks! 😸

2reactions
pllimcommented, Oct 22, 2022

This only affects the tests, so I don’t think change logs are needed.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to use temporary directories and files in tests
You can use the tmp_path fixture which will provide a temporary directory unique to the test invocation, created in the base temporary directory....
Read more >
Creating a temporary directory in PyTest - python
You can use the tmpdir fixture which will provide a temporary directory unique to the test invocation, created in the base temporary directory....
Read more >
Python: PyTest fixtures - temporary directory - tmpdir
PyTest has a rich set of Fixures, one of the, called tmpdir makes it easy to create a temporary diriectory for each test...
Read more >
`tmp_path` and `tmpdir` doesn't share the same temporary ...
I expected that the fixtures will operate on the same directory. ... Replace tmpdir fixture with tmp_path in tests aio-libs/aiohttp#3551.
Read more >
Using tmpdir and tmpdir_factory
The tmpdir and tmpdir_factory builtin fixtures are used to create a temporary file system directory before your test runs, and remove the directory...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found