pytest-dev / pytest-cov

Coverage plugin for pytest.
MIT License
1.76k stars 211 forks source link

module docstirng reported as missing [misbehave] #171

Open 1oglop1 opened 7 years ago

1oglop1 commented 7 years ago

OS: OSx 10.12.6 coverage (4.4.1) pytest-cov (2.5.1)

I'm learning how to use coverage and pytest-cov and it reports very strange things. Missing coverage on docstring example:

#!/usr/bin/env python 
# -*- coding: utf-8 -*- 
""" 
__main__.py file of jans_sample_python_package package. 

__main__.py is run as '__main__' when you run a package as the main program. 
For instance, python -m jans_sample_python_package 
""" 

Coverage report: https://1oglop1.github.io/jan_cov/src_jans_sample_python_package___main___py.html

Code: https://github.com/1oglop1/covjan/tree/cov2

Can someone please tell me what's wrong or what to read in order to learn more how does this all work together?

ionelmc commented 7 years ago

@1oglop1 it would appear that the code ain't covered at all? What happens if you remove the # pragma: no cover from the main function?

1oglop1 commented 7 years ago

@icemac Then the result is: 12 statements 0 run 12 missing 0 excluded

Is there anything I can debug or provide you more input?

ionelmc commented 7 years ago

Seems to work as expected - you don't test the jans_sample_python_package.__main__ module at all. To do it, run subprocess.check_output([sys.executable, '-mjans_sample_python_package']) or something similar.

1oglop1 commented 7 years ago

Yey, that fixt the report! Huge thanks! How about line 3 why """ is reported was missing?

ionelmc commented 7 years ago

Module ain't imported, so why would it be covered?