pytest-cov
pytest-cov copied to clipboard
pytorch subclass of torch.autograd.Function's backward can be traced by pytest-cov
Summary
According to the log, the backward function in subclass of torch.autograd.Function has been executed. but pytest-cov reports this function is missing.

please help me check this problem, why it happened. Thank you very much.
Versions
pytest=7.1.2 pytest-cov=3.0.0
Config
setup.cfg
# pytest-cov config
[coverage:run]
branch = True
omit =
# exclude some file that should not be tested
*/test_*.py
*/*_test.py
[coverage:report]
# result precision
precision = 2
exclude_lines =
# Don't complain about missing debug-only code:
if __name__ == .__main__.:
[coverage:html]
# report output dir
directory = ./tests/report/cov
Code
class Test(torch.autograd.Function):
@staticmethod
def forward(ctx, x):
return x
@staticmethod
def backward(ctx,grad_out):
return grad_out
test = Test.apply
input = torch.randn(2,3)
output = test(input)
output.backward(torch.ones_like(output))
This will be a problem due to coverage.py and its interactions with PyTorch. I thought there was an issue already about it, but I don't see it now. Feel free to open an issue there: https://github.com/nedbat/coveragepy/issues/new/choose