Error from pytest-profiling when doing a 'chdir' in a test
See original GitHub issuePytest-profiling (version 1.2.2) is working well on my 2 machines (Windows and Mac OSX).
However, when a test contains a os.chdir
, the following error is raised:
self = <pytest_profiling.Profiling object at 0x10c744910>, item = <Function 'test_chdir[dir1]'>
@pytest.hookimpl(hookwrapper=True)
def pytest_runtest_call(self, item):
prof = cProfile.Profile()
prof.enable()
yield
prof.disable()
prof_filename = os.path.join("prof", clean_filename(item.name) + ".prof")
try:
> prof.dump_stats(prof_filename)
/Library/Python/2.7/site-packages/pytest_profiling.py:68:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <cProfile.Profile object at 0x10c780c20>, file = 'prof/test_chdir[dir1].prof'
def dump_stats(self, file):
import marshal
> f = open(file, 'wb')
E IOError: [Errno 2] No such file or directory: u'prof/test_chdir[dir1].prof'
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/cProfile.py:85: IOError
The code I used to reproduce the issue is the following
import pytest
import os
from time import sleep
@pytest.mark.parametrize("dir", [
"dir1", "dir2", "NewFolder"
])
def test_chdir(dir):
try: os.mkdir(dir)
except: pass
sleep(0.3)
try:
os.chdir(dir)
except Exception as e:
assert False, "Error while going to directory '{}': {}".format(dir, e)
Issue Analytics
- State:
- Created 7 years ago
- Comments:7 (4 by maintainers)
Top Results From Across the Web
Error from pytest-profiling when doing a 'chdir' in a test #40
Pytest-profiling (version 1.2.2) is working well on my 2 machines (Windows and Mac OSX). However, when a test contains a os.chdir, the following...
Read more >Why does os.chdir generate an error when running doctest in ...
I'm using the testfixtures library for the first time. Using it to test a function that creates a directory. Am getting the below...
Read more >pytest-profiling - PyPI
Profiling plugin for pytest, with tabular and heat graph output. Tests are profiled with cProfile and analysed with pstats; heat graphs are generated...
Read more >pytest-profiling - Python Package Health Analysis - Snyk
Tests are profiled with cProfile and analysed with pstats; heat graphs are generated using gprof2dot and dot. Installation. Install using your favourite package ......
Read more >pytest Documentation - Read the Docs
(See Demo of Python failure reports with pytest). ... pytest rewrites test modules on import by using an import hook to write new...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hello @eeaston and thank for maintaining this plugin!
I am having the same issue.
In my case, it is the use of
chdir
with a temporary directory that causes the error. I have a tool that relies on agetcwd()
, so I use a fixture to create a tempdir, chdir into it, and then destroy the tempdir at the end. That causes the.prof
to go missingHere is a min repro:
Test w/out --profile passes
Test w/ profile - Traceback
@jfthuong can you confirm it works for you now?