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

@profile does not play well with pytest #27

Open
mgedmin opened this issue Sep 17, 2020 · 0 comments
Open

@profile does not play well with pytest #27

mgedmin opened this issue Sep 17, 2020 · 0 comments

Comments

@mgedmin
Copy link
Owner

mgedmin commented Sep 17, 2020

if I drop a


from profilehooks import profile
@profile
def test_something():
    ...

in a pytest test file and run pytest, I get this failure:

*** PROFILER RESULTS ***
test_search_by_title (/home/mg/Private/tilaajavastuu/bol/server/test/views/test_companies.py:200)
function called 1 times

Error in atexit._run_exitfuncs:
Traceback (most recent call last):
  File ".../env/lib/python3.8/site-packages/profilehooks.py", line 411, in atexit
    self.print_stats()
  File ".../env/lib/python3.8/site-packages/profilehooks.py", line 394, in print_stats
    stats.print_stats(self.entries)
  File "/usr/lib/python3.8/pstats.py", line 369, in print_stats
    print(indent, self.total_calls, "function calls", end=' ', file=self.stream)
  File ".../env/lib/python3.8/site-packages/_pytest/capture.py", line 415, in write
    self.buffer.write(obj)
ValueError: I/O operation on closed file

And if I do @profile(immediate=True), I see nothing at all (because pytest captures it), unless I also use pytest -s.

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

No branches or pull requests

1 participant