coveragepy icon indicating copy to clipboard operation
coveragepy copied to clipboard

Delete after generating files in the test phase. coverage will raise no such file or directory error

Open Tritium-leo opened this issue 3 years ago • 1 comments

Describe the bug Delete after generating files in the test phase

I generated files during the test phase and then deleted them. When outputting the results, coverage scans them. Then, in xmlreport, filenotfounderror: [errno 2] no such file or directory Call HTML_ Report will not make an error

I tried to use omit to filter my temporary file directory, but it didn't work

To Reproduce python 3 .10 coverage: 6.4.4 FileNorFoundError:[Errno 2] No such file or directory

Additional context

conv = coverage.coverage(
            omit=["*/autoname*/*", './autoname*/*'],
)
conv.start()
for p in paths:
    discover = unittest.TestLoader().discover(str(p), "test*.py")
    _ = runner.run(discover)
conv.stop()
conv.save()
conv.xml_report(outfile=env.coverage_xml_report_path)
try:
    net.save_state()
    dir_path = Path(os.getcwd()).joinpath(net.name if net.name else 'autoname').joinpath(
        'parameters')
    filename = "_parameters_dict.pt"
    file_path = dir_path.joinpath(filename)
    self.assertTrue(file_path.exists())
finally:
    if dir_path.exists():
        shutil.rmtree(dir_path.parent)
  File "/tests/main.py", line 82, in main
    conv.xml_report(outfile=env.coverage_xml_report_path)
  File "/venv/lib/python3.10/site-packages/coverage/control.py", line 1052, in xml_report
    return render_report(self.config.xml_output, XmlReporter(self), morfs, self._message)
  File "/venv/lib/python3.10/site-packages/coverage/report.py", line 35, in render_report
    return reporter.report(morfs, outfile=outfile)
  File "/venv/lib/python3.10/site-packages/coverage/xmlreport.py", line 76, in report
    for fr, analysis in get_analysis_to_report(self.coverage, morfs):
  File "/venv/lib/python3.10/site-packages/coverage/report.py", line 64, in get_analysis_to_report
    matcher = FnmatchMatcher(prep_patterns(config.report_omit), "report_omit")
  File "/venv/lib/python3.10/site-packages/coverage/files.py", line 189, in prep_patterns
    prepped.append(abs_file(p))
  File "/venv/lib/python3.10/site-packages/coverage/files.py", line 154, in abs_file
    return actual_path(os.path.abspath(os.path.realpath(path)))
  File "/usr/lib/python3.10/posixpath.py", line 396, in realpath
    return abspath(path)
  File "/usr/lib/python3.10/posixpath.py", line 383, in abspath
    cwd = os.getcwd()
FileNotFoundError: [Errno 2] No such file or directory

Error line : conv.xml_report(outfile=env.coverage_xml_report_path) but if use it's work: conv.html_report(directory=str(env.coverage_report_path)) If I don't delete the directory, there will be no error

if omit=["*/autoname*"]

Traceback (most recent call last):
  File "tests/main.py", line 82, in main
    conv.xml_report(outfile=env.coverage_xml_report_path)
  File "venv/lib/python3.10/site-packages/coverage/control.py", line 1052, in xml_report
    return render_report(self.config.xml_output, XmlReporter(self), morfs, self._message)
  File "venv/lib/python3.10/site-packages/coverage/report.py", line 35, in render_report
    return reporter.report(morfs, outfile=outfile)
  File "venv/lib/python3.10/site-packages/coverage/xmlreport.py", line 77, in report
    self.xml_file(fr, analysis, has_arcs)
  File "venv/lib/python3.10/site-packages/coverage/xmlreport.py", line 174, in xml_file
    xclass.setAttribute("name", os.path.relpath(rel_name, dirname))
  File "/usr/lib/python3.10/posixpath.py", line 487, in relpath
    start_list = [x for x in abspath(start).split(sep) if x]
  File "/usr/lib/python3.10/posixpath.py", line 383, in abspath
    cwd = os.getcwd()
FileNotFoundError: [Errno 2] No such file or directory

Process finished with exit code 1

Tritium-leo avatar Sep 02 '22 02:09 Tritium-leo

Can you give me a repo that I can use to reproduce the problem? It will be easier to see all the details that way.

nedbat avatar Sep 02 '22 11:09 nedbat

I don't understand why you are deleting a directory you need. If you can provide more details, feel free to re-open this issue.

nedbat avatar Nov 03 '22 10:11 nedbat