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

pytest error: tempfile.py:368: FileNotFoundError #862

Closed
tomkinsc opened this issue Jul 23, 2018 · 9 comments
Closed

pytest error: tempfile.py:368: FileNotFoundError #862

tomkinsc opened this issue Jul 23, 2018 · 9 comments
Assignees

Comments

@tomkinsc
Copy link
Member

tomkinsc commented Jul 23, 2018

This may be related to changes introduced in #840.

When running pytest, the fixtures responsible for creating temp directories can attempt to create a temp directory within a containing directory that does not exist, resulting in an error from tempfile.py: tempfile.py:368: FileNotFoundError

How to reproduce (once the expected test output has been updated to what GenBank now returns):
Within test/integration/test_ncbi.py, change skip_test = True to skip_test = False.
Then run:
pytest test/integration/test_ncbi.py
Note that the issue does not appear when calling one of the test classes directly.
(ex. pytest test/integration/test_ncbi.py::TestFastaFetch).

Potentially relevant from the pytest changelog is a change in pytest 3.3.0 related to testdir /tmpdir: pytest-dev/pytest#2751
Maybe with the upgrade to pytest 3.6.3 in #856, we no longer need the custom tmpdir fixtures in conftest.py?

@dpark01
Copy link
Member

dpark01 commented Jul 23, 2018

If you think our custom fixtures could be eliminated by using newly available features in the latest pytest, I’m all for reducing our custom test code.

@tomkinsc
Copy link
Member Author

It's worth trying, but since the custom fixtures were added to squash a bug that appeared only intermittently it would be helpful to have @notestaff take a look since he was able to reliably reproduce the issue (by running pytest many times?).

@dpark01
Copy link
Member

dpark01 commented Jul 23, 2018

Yeah I actually don’t remember why we have these custom fixtures.. I just remember we tweaked them recently.

@yesimon
Copy link
Contributor

yesimon commented Jul 24, 2018

pytest doesn't have great handling for ordering tmpfile generation, which was the original purpose to order the module vs function vs session level tmpfiles.

@notestaff
Copy link
Contributor

also, pytest doesn't use mkdtemp, which is the safer way to create temdirs.
also, using own fixtures lets us preserve the tempdirs during testing by setting an env var.

i'll push the PR fixing this shortly, the changes are at https://github.com/broadinstitute/viral-ngs/compare/is-fix-test-tempfiles

@tomkinsc
Copy link
Member Author

How should we access the tempdir within a test class method, tempfile.gettempdir()? Do we really need to add an ugly pytest fixture for it?

@notestaff
Copy link
Contributor

I'm not sure I understand. In what way is adding a test method parameter uglier than adding a line of code that calls tempfile.gettempdir()?

@tomkinsc
Copy link
Member Author

tomkinsc commented Jul 24, 2018

IMHO, pytest's param-like fixtures can be ambiguous since it is not always clear where they are defined, especially if in a different scope. The nativeunittest module has setUp() setUpClass(), which are at least in-scope.

@notestaff
Copy link
Contributor

While fixtures can get implicitly imported from conftest.py, which can be at the root or in a local dir, it's not the same level of bad as "from X import *", since if it's not local it's in one of the few conftest.py .

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

No branches or pull requests

4 participants