Closed gabrieleballetti closed 1 year ago
It turns out that this issue is probably caused by some bad interactions between pytest and the click.testing module (typer.testing is build on top of that). From the CliRunner docs:
This only works in single-threaded systems without any concurrency as it changes the global interpreter state.
The fact that clearml spins new threads, together with some poor handling from pytest and some not completely understood interaction with tensorflow seems to cause the issue. I solved by parsing manually cl arguments and calling the command function manually instead.
Might be that something could be done on the clearml side, but I consider this closed.
Describe the bug
We test our ClearML integration with pytest. Under certain circumstances pytest raises an exception
ValueError: I/O operation on closed file
on a test whereTask.init()
gets called. I suppose that some resources are not disposed correctly, but I struggle going through the pytest code and I haven't found a way around it beside disabling ClearML for that test, which I really would like to avoid.To reproduce
Below the content of
test.py
.Then run
pytest test.py
. This runstest_task()
which invokes (through typer) the main function. Surprisingly, that import of tensorflow is needed to make it crash!Environment