Search code examples
pythonunit-testingtensorflowkerascoverage.py

Coverage.py returns error "No source for code:..." when running tensorflow.keras.model.fit function


I have built unittests for my code and everything works fine when running them from vscode. Even running coverage run runs successfully. But when I try to run coverage report I get the following output:

No source for code: 'C:\Users\XXX\AppData\Local\Temp\1\__autograph_generated_file4ilniiln.py'

I found out that this happens exactly when I add a test case which contains tensorflow.keras.Model.fit function. If I remove tensorflow.keras.Model.fit then this message does not appear for coverage report command.

How can I solve this issue?


Solution

  • Tensorflow rewrites your code and runs it from a new location. I need some assistance to get it working properly in coverage.py. See this issue for details: https://github.com/nedbat/coveragepy/issues/856

    You can try using the -i flag to coverage report to ignore files it can't find. I don't know if you will still get complete data or not.