facebookincubator / ptr

Python Test Runner.
MIT License
284 stars 15 forks source link

Look at why Space in py_modules path breaks ptr #30

Open cooperlees opened 5 years ago

cooperlees commented 5 years ago

Thanks for logging an issue with ptr. Here are some questions to help try and pull out as much information possible to help us help you!

How is ptr not doing what you expect?

I would of expected pathlib to handle this

What is your suggestion to make this better?

Unfortunately support spaces or see why pathlib does not.

Code/Bug example?

/tmp/workspace/PYTHON ptr_terragraph_ansbible/nmap_to_scuba/nts.py                    143     75    48%   36-41, 80-87, 107-130, 136-170, 178-196, 239-255, 259
/tmp/workspace/PYTHON ptr_terragraph_ansbible/nmap_to_scuba/nts_tests.py               29      0   100%
/tmp/workspace/PYTHON ptr_terragraph_ansbible/nmap_to_scuba/nts_tests_fixtures.py       4      0   100%
-----------------------------------------------------------------------------------------------------------------
TOTAL                                                                               10381   7339    29%
[2019-02-19 16:26:05,058] ERROR: Unable to find path relative path for /tmp/workspace/PYTHON (ptr.py:147)
[2019-02-19 16:26:05,059] ERROR: Unable to find path relative path for /tmp/workspace/PYTHON (ptr.py:147)
[2019-02-19 16:26:05,059] ERROR: Unable to find path relative path for /tmp/workspace/PYTHON (ptr.py:147)

Traceback (most recent call last):
  File "/tmp/ptr_terragraph_ansible/bin/ptr", line 11, in <module>
    sys.exit(main())
  File "/tmp/ptr_terragraph_ansible/lib/python3.6/site-packages/ptr.py", line 880, in main
    args.stats_file,
  File "/usr/lib/python3.6/asyncio/base_events.py", line 467, in run_until_complete
    return future.result()
  File "/tmp/ptr_terragraph_ansible/lib/python3.6/site-packages/ptr.py", line 813, in async_main
    stats_file,
  File "/tmp/ptr_terragraph_ansible/lib/python3.6/site-packages/ptr.py", line 761, in run_tests
    await asyncio.gather(*consumers)
  File "/tmp/ptr_terragraph_ansible/lib/python3.6/site-packages/ptr.py", line 547, in _test_runner
    print_cov,
  File "/tmp/ptr_terragraph_ansible/lib/python3.6/site-packages/ptr.py", line 500, in _test_steps_runner
    stats,
  File "/tmp/ptr_terragraph_ansible/lib/python3.6/site-packages/ptr.py", line 171, in _analyze_coverage
    if coverage_lines[afile].cover < cov_req:
KeyError: 'nts.py'

How can a developer reproduce this?

Add a unittest with a path to some code with a space in it.

cooperlees commented 5 years ago

So this fails because I was lazy and parsed the human output of coverage as it made some thing easier for me. I use split on white space, and get all the coverage output as one str due to using maxsplits. Only way I can see how to sanely fix this is to parse the XML and reconstruct the output from the XML.

amyreese commented 5 years ago

it might be easier to just parse stdout with a simple regex that expects some number of numeric fields, and capture everything before the first numeric field (minus trailing whitespace) as the filename.