Open vvasuki opened 4 years ago
I encountered the same issue. The following alternative works:
Same problem, here is my alternative:
I use timebudget
as a dev dependency, so the context manager has to default to a contextlib.nullcontext
in production mode. While testing with pytest (also in the dev environment) I get the same ValueError: I/O operation on closed file.
Error. Therefore I use sys.modules
to check if pytest is running:
# File mylib.timing.py
try:
import sys as __sys
from timebudget import timebudget as timed
timed.set_quiet()
if "pytest" not in __sys.modules:
timed.report_at_exit()
except ImportError:
from contextlib import nullcontext as timed
# File mylib.foo.py
from mylib.timing import timed
@timed
def func_to_be_timed():
...
The below illustrates the problem
Settings used: