Coverage trips when using the statistics module

Issue #326 invalid
Former user created an issue

Python 3.4 introduced a new statistics module, when importing it in my code, I get a report like the following:

Name                     Stmts   Miss  Cover   Missing
------------------------------------------------------
decimal                   2601   2601     0%   16-6406
[... my stuff ...]
fractions                  257    257     0%   4-630
numbers                    136    136     0%   4-394
statistics                 175    175     0%   18-595
------------------------------------------------------
TOTAL                     3676   3169    14%   
python3.4 -m coverage --version
Coverage.py, version 3.7.1.  http://nedbatchelder.com/code/coverage

Comments (7)

  1. Bengt Lüers

    Sure:

    $ python3.4 -m nose --with-coverage --verbose --all-modules test.py
    test.test ... ok
    
    Name         Stmts   Miss  Cover   Missing
    ------------------------------------------
    decimal       2601   2601     0%   16-6406
    fractions      257    257     0%   4-630
    numbers        136    136     0%   4-394
    statistics     175    175     0%   18-595
    ------------------------------------------
    TOTAL         3169   3169     0%   
    ----------------------------------------------------------------------
    Ran 1 test in 0.001s
    
    OK
    

    test.py

    import statistics
    
    def average(iterable):
        return statistics.mean(iterable)
    
    def test():
        assert average([1, 2, 3]) == 2
    
  2. Ned Batchelder repo owner

    Hmm, your output is odd in that it doesn't show "test.py" in the output, I guess because the --with-cover plugin tries to skip test files. I get this:

    $ python3.4 -m nose --with-coverage --verbose --all-modules bug326.py
    bug326.test ... ok
    
    Name         Stmts   Miss  Cover   Missing
    ------------------------------------------
    bug326           5      0   100%
    decimal       2601   2601     0%   16-6406
    fractions      257    257     0%   4-630
    numbers        136    136     0%   4-394
    statistics     175    175     0%   18-595
    ------------------------------------------
    TOTAL         3174   3169     1%
    ----------------------------------------------------------------------
    Ran 1 test in 0.001s
    
    OK
    

    I think this is an artifact of the nose plugin. When I run directly with coverage, I get these results:

    $ coverage run bug326.py
    $ coverage report
    Name     Stmts   Miss  Cover
    ----------------------------
    bug326       5      2    60%
    

    and:

    $ coverage run --pylib bug326.py
    $ coverage report
    Name                                                                          Stmts   Miss  Cover
    -------------------------------------------------------------------------------------------------
    /usr/local/pythonz/pythons/CPython-3.4.0/lib/python3.4/_weakrefset              146    116    21%
    /usr/local/pythonz/pythons/CPython-3.4.0/lib/python3.4/abc                       92     57    38%
    /usr/local/pythonz/pythons/CPython-3.4.0/lib/python3.4/codecs                   396    389     2%
    /usr/local/pythonz/pythons/CPython-3.4.0/lib/python3.4/collections/__init__     598    577     4%
    /usr/local/pythonz/pythons/CPython-3.4.0/lib/python3.4/posixpath                271    229    15%
    /usr/local/pythonz/pythons/CPython-3.4.0/lib/python3.4/re                       143    129    10%
    /usr/local/pythonz/pythons/CPython-3.4.0/lib/python3.4/sre_compile              355    156    56%
    /usr/local/pythonz/pythons/CPython-3.4.0/lib/python3.4/sre_parse                666    421    37%
    /usr/local/pythonz/pythons/CPython-3.4.0/lib/python3.4/tokenize                 388    361     7%
    /usr/local/pythonz/pythons/CPython-3.4.1/lib/python3.4/decimal                 2601   2188    16%
    /usr/local/pythonz/pythons/CPython-3.4.1/lib/python3.4/fractions                257    195    24%
    /usr/local/pythonz/pythons/CPython-3.4.1/lib/python3.4/imp                      153    152     1%
    /usr/local/pythonz/pythons/CPython-3.4.1/lib/python3.4/numbers                  136     56    59%
    /usr/local/pythonz/pythons/CPython-3.4.1/lib/python3.4/statistics               175    151    14%
    /usr/local/pythonz/pythons/CPython-3.4.1/lib/python3.4/threading                582    581     1%
    bug326                                                                            5      2    60%
    -------------------------------------------------------------------------------------------------
    TOTAL                                                                          6964   5760    17%
    

    (though I do wonder why some of my stdlib is coming from 3.4.0 and others from 3.4.1....)

  3. Bengt Lüers

    I can recreate your results when renaming test.py to bug326.py.

    My report looks even different, with an unspecific /python3.4/ showing up:

    $  coverage run --pylib bug326.py
    $ coverage report
    Name                                            Stmts   Miss  Cover
    -------------------------------------------------------------------
    /usr/local/lib/python3.4/_weakrefset              146    116    21%
    /usr/local/lib/python3.4/abc                       92     57    38%
    /usr/local/lib/python3.4/codecs                   396    389     2%
    /usr/local/lib/python3.4/collections/__init__     598    577     4%
    /usr/local/lib/python3.4/decimal                 2601   2188    16%
    /usr/local/lib/python3.4/fractions                257    195    24%
    /usr/local/lib/python3.4/imp                      153    152     1%
    /usr/local/lib/python3.4/numbers                  136     56    59%
    /usr/local/lib/python3.4/posixpath                272    230    15%
    /usr/local/lib/python3.4/re                       143    129    10%
    /usr/local/lib/python3.4/sre_compile              355    156    56%
    /usr/local/lib/python3.4/sre_parse                665    420    37%
    /usr/local/lib/python3.4/statistics               175    151    14%
    /usr/local/lib/python3.4/threading                582    581     1%
    /usr/local/lib/python3.4/tokenize                 392    365     7%
    bug326                                              5      2    60%
    -------------------------------------------------------------------
    TOTAL                                            6968   5764    17%
    

    So, yes, coverage does indeed seem to work properly. I will report this over at nose. Thanks so far.

  4. Log in to comment