Skip to content

pytest-cov makes test fail by putting a temporary file into cwd #77

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
ThomasWaldmann opened this issue Aug 8, 2015 · 11 comments
Closed
Labels

Comments

@ThomasWaldmann
Copy link

i have tests that check if some specific files have been extracted into cwd.
they fail when using pytest-cov because some .coverage* file gets created there.

is there any way to avoid this?

@ThomasWaldmann ThomasWaldmann changed the title pytest-cov make test fail by putting a temporary file into cwd pytest-cov makes test fail by putting a temporary file into cwd Aug 8, 2015
@ionelmc
Copy link
Member

ionelmc commented Aug 8, 2015

Have you tried to set something like this in .coveragerc?

[run]
data_file = /tmp/.coverage

@ThomasWaldmann
Copy link
Author

Thanks for the pointer, I tried it:

Still getting this failing test:

AssertionError: Lists differ: ['.coverage.testing-worker-lin... != ['file2']

Hmm, maybe this is not a temporary file of coverage, but a lock/pid file of pytest-cov?

@ionelmc
Copy link
Member

ionelmc commented Aug 8, 2015

Strange. Are you using xdist? That file name appears to be suffixed from here

@ThomasWaldmann
Copy link
Author

Well, not by myself / not knowingly, but the tests run on travis-ci.org and they somehow have 1 worker per test environment.

@ionelmc
Copy link
Member

ionelmc commented Aug 8, 2015

Can you post a link to the build?

On Saturday, August 8, 2015, TW [email protected] wrote:

Well, not by myself / not knowingly, but the tests run on travis-ci.org
and they somehow have 1 worker per test environment.


Reply to this email directly or view it on GitHub
#77 (comment)
.

Thanks,
-- Ionel Cristian Mărieș, http://blog.ionelmc.ro

@ThomasWaldmann
Copy link
Author

@ThomasWaldmann
Copy link
Author

https://travis-ci.org/borgbackup/borg/builds/74696354 < hah! was just some vague feeling, that I maybe should try <2.0.0 - and it works now! :)

@ionelmc
Copy link
Member

ionelmc commented Aug 8, 2015

Having a hard time figuring out how the reproduce your issue. IOW, data_file works as expected for me (going to add a test for this soon).

Do you do anything special for coverage configuration (besides having a .coveragerc)?

@ThomasWaldmann
Copy link
Author

Well, the test fail issue just went away as soon as I put <2.0.0 in my requirements file.
So it seems it is not creating this file there any more.
I tried with data_file before, but somehow I couldn't solve with that. Part of the issue is that maybe codecov expects the result file to be .coverage in the toplevel dir of the project.

@ionelmc
Copy link
Member

ionelmc commented Aug 9, 2015

I've managed to get your project to work as expected, see:
https://travis-ci.org/ionelmc/borg/jobs/74795190

Diff: borgbackup/borg@master...ionelmc:master

The esential parts:

  • data_file and perhaps parallel(not sure if parallel changes anything
    but you should have it anyway)
  • --cov-config because you seems to do weird stuff in your tests wrt the
    current directory and that gets pytest-cov confused

I think the real bug here is that pytest-cov forgets about the .coveragerc
if you change the cwd. I'll investigate more later, but you have a solution
above right now :-)

Thanks,
-- Ionel Cristian Mărieș, http://blog.ionelmc.ro

On Sun, Aug 9, 2015 at 1:22 PM, TW [email protected] wrote:

Well, the test fail issue just went away as soon as I put <2.0.0 in my
requirements file.
So it seems it is not creating this file there any more.
I tried with data_file before, but somehow I couldn't solve with that.
Part of the issue is that maybe codecov expects the result file to be
.coverage in the toplevel dir of the project.


Reply to this email directly or view it on GitHub
#77 (comment)
.

ionelmc added a commit that referenced this issue Oct 1, 2015
Use absolute paths for coverage config file and sources. Add a new internal variable "COV_CORE_DATAFILE" to workaround the misplacement of .coverage.foobar.123 files.

Because needs to be an absolute path COV_CORE_CONFIG we need to do some special things: coverage treats config_file='.coveragerc' as if it was config_file=True. We need to keep that behavior.

Closes #94. Closes #77.
@ionelmc ionelmc added the bug label Oct 1, 2015
@ionelmc
Copy link
Member

ionelmc commented Oct 1, 2015

The cwd change issue is getting fixed in #95 if you wanna give it a try.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants