Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

.pyw files aren't reported properly #261

Closed
nedbat opened this issue Sep 11, 2013 · 3 comments
Closed

.pyw files aren't reported properly #261

nedbat opened this issue Sep 11, 2013 · 3 comments
Labels
bug Something isn't working report

Comments

@nedbat
Copy link
Owner

nedbat commented Sep 11, 2013

[Reported by Timothy Wasserman]

(OS = Win7, Coverage version = 3.6, Python = 2.7.3, wxPython = 2.8.12.1)

I’m working on a wxPython app in windows, and I’ve given some of my source files the .pyw extension so that they open without a console window.

From the command prompt, when I do ‘coverage run test_mop.py’ it runs without complaint, but when I subsequently try ‘coverage report’ it gives me a NoSource error like this:

C:\Users\twasserm\Desktop\workspace\FDS\test>coverage report

Name                                                  Stmts   Miss  Cover
-------------------------------------------------------------------------
C:\Users\twasserm\Desktop\workspace\FDS\src\fdsutil      49     25    49%
C:\Users\twasserm\Desktop\workspace\FDS\src\mop   NoSource: No source for code: 'C:\Users\twasserm\Desktop\workspace\FDS\src\mop.py'
test_mop                                                 44      0   100%
-------------------------------------------------------------------------
TOTAL                                                    93     25    73%

The mop.py source file that coverage report is looking for is actually mop.pyw. fdsutil has a standard .py extension and is correctly processed. When I make a copy of mop.pyw as mop.py, ‘coverage report’ picks it up immediately (without having to do coverage run again):

C:\Users\twasserm\Desktop\workspace\FDS\test>coverage report
Name                                                  Stmts   Miss  Cover
-------------------------------------------------------------------------
C:\Users\twasserm\Desktop\workspace\FDS\src\fdsutil      49     25    49%
C:\Users\twasserm\Desktop\workspace\FDS\src\mop         121     73    40%
test_mop                                                 44      0   100%
-------------------------------------------------------------------------
TOTAL                                                   214     98    54%

@nedbat
Copy link
Owner Author

nedbat commented Sep 29, 2013

Commit 783923fd9ccccbb (bb) helped some with this.

@nedbat
Copy link
Owner Author

nedbat commented Sep 29, 2013

Fixed in 4417e335f3e4 (bb)

@nedbat
Copy link
Owner Author

nedbat commented Feb 26, 2014

Original comment by Okko Willeboordse (Bitbucket: owillebo, GitHub: owillebo)


==============
Update;
Now using version 4.0.3 and this version solves problem described below.

I have two files;

test.py;

#!python
import coverage
cov = coverage.coverage(source = ['target'])
cov.start()
import target
cov.stop()
print cov.html_report()

and target.py(w);

#!python
def foo():
  pass

When I run test.py with target.py it outputs, as expected;

50.0

But when I rename target.py in to target.pyw, test.py outputs;

#!python
Coverage.py warning: Module target has no Python source.
Coverage.py warning: No data was collected.
Traceback (most recent call last):
  File "test.py", line 6, in <module>
    print cov.html_report()
  File "c:\Python27\lib\site-packages\coverage\control.py", line 662, in html_report
    return reporter.report(morfs)
  File "c:\Python27\lib\site-packages\coverage\html.py", line 113, in report
    self.report_files(self.html_file, morfs, self.config.html_dir)
  File "c:\Python27\lib\site-packages\coverage\report.py", line 76, in report_files
    raise CoverageException("No data to report.")
coverage.misc.CoverageException: No data to report.

How do I run coverage programmatically with .pyw files?

Note that Python imports test(.pyw) just the same.

@nedbat nedbat closed this as completed Feb 26, 2014
@nedbat nedbat added major bug Something isn't working report labels Jun 23, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working report
Projects
None yet
Development

No branches or pull requests

1 participant