This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Assertion failure when running "test_ast" tests with coverage.
Type: Stage: resolved
Components: Tests Versions: Python 3.6
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: Quentin.Pradet, SilentGhost, ap, benjamin.peterson, georg.brandl, levkivskyi, ned.deily, python-dev
Priority: normal Keywords:

Created on 2016-07-22 22:32 by ap, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (8)
msg271038 - (view) Author: (ap) Date: 2016-07-22 22:32
This is with a build of the default branch on OS X 10.11.6:

$ hg identify
fada654c5f72 tip
$ ./python.exe --version
Python 3.6.0a3+
$

The "test_ast" tests appear to run fine without coverage tracking enabled:

$ ./python.exe -m test test_ast
Run tests sequentially
0:00:00 [1/1] test_ast
1 test OK.
Total duration: 0:00:07
$

But when coverage tracking is enabled, an assertion fails:

$ ./python.exe -m test --coverage -D`pwd`/coverage_data test_ast
Run tests sequentially
0:00:00 [1/1] test_ast
Assertion failed: (line > 0), function _PyCode_CheckLineNumber, file Objects/codeobject.c, line 717.
Fatal Python error: Aborted

Current thread 0x00007fff76279000 (most recent call first):
  File "test", line 0 in <module>
  File "/python-dev/cpython/Lib/test/test_ast.py", line 559 in test_level_as_none
  File "/python-dev/cpython/Lib/unittest/case.py", line 600 in run
  File "/python-dev/cpython/Lib/unittest/case.py", line 648 in __call__
  File "/python-dev/cpython/Lib/unittest/suite.py", line 122 in run
  File "/python-dev/cpython/Lib/unittest/suite.py", line 84 in __call__
  File "/python-dev/cpython/Lib/unittest/suite.py", line 122 in run
  File "/python-dev/cpython/Lib/unittest/suite.py", line 84 in __call__
  File "/python-dev/cpython/Lib/unittest/suite.py", line 122 in run
  File "/python-dev/cpython/Lib/unittest/suite.py", line 84 in __call__
  File "/python-dev/cpython/Lib/test/support/__init__.py", line 1709 in run
  File "/python-dev/cpython/Lib/test/support/__init__.py", line 1810 in _run_suite
  File "/python-dev/cpython/Lib/test/support/__init__.py", line 1844 in run_unittest
  File "/python-dev/cpython/Lib/test/libregrtest/runtest.py", line 179 in test_runner
  File "/python-dev/cpython/Lib/test/libregrtest/runtest.py", line 180 in runtest_inner
  File "/python-dev/cpython/Lib/test/libregrtest/runtest.py", line 144 in runtest
  File "<string>", line 1 in <module>
  File "/python-dev/cpython/Lib/trace.py", line 469 in runctx
  File "/python-dev/cpython/Lib/test/libregrtest/main.py", line 330 in run_tests_sequential
  File "/python-dev/cpython/Lib/test/libregrtest/main.py", line 406 in run_tests
  File "/python-dev/cpython/Lib/test/libregrtest/main.py", line 466 in _main
  File "/python-dev/cpython/Lib/test/libregrtest/main.py", line 446 in main
  File "/python-dev/cpython/Lib/test/libregrtest/main.py", line 508 in main
  File "/python-dev/cpython/Lib/test/__main__.py", line 2 in <module>
  File "/python-dev/cpython/Lib/runpy.py", line 85 in _run_code
  File "/python-dev/cpython/Lib/runpy.py", line 184 in _run_module_as_main
Abort trap: 6
$
msg271891 - (view) Author: SilentGhost (SilentGhost) * (Python triager) Date: 2016-08-03 10:45
Cannot reproduce this on Linux
msg272527 - (view) Author: Ivan Levkivskyi (levkivskyi) * (Python committer) Date: 2016-08-12 11:54
You could try changing this line in compile.c (in function 'assemble')

if (entryblock && entryblock->b_instr)

to

if (entryblock && entryblock->b_instr && entryblock->b_instr->i_lineno)

Does this help?
msg272549 - (view) Author: Quentin Pradet (Quentin.Pradet) * Date: 2016-08-12 17:39
Thanks levkivskyi, it fixed the issue for me!
msg272859 - (view) Author: (ap) Date: 2016-08-16 14:24
Thanks, Ivan, that change fixes it for me, too.

I checked with a more recent revision and build:

$ hg identify
265644bad99e+ tip
$ ./python.exe --version
Python 3.6.0a4+
$ 

Confirmed that it still exhibited the same behaviour as before:

$ ./python.exe -m test test_ast
Run tests sequentially
0:00:00 [1/1] test_ast
1 test OK.
Total duration: 0:00:06
$ 

$ ./python.exe -m test --coverage -D`pwd`/coverage_data test_ast
Run tests sequentially
0:00:00 [1/1] test_ast
Assertion failed: (line > 0), function _PyCode_CheckLineNumber, file Objects/codeobject.c, line 717.
Fatal Python error: Aborted

Current thread 0x00007fff7b5a7000 (most recent call first):
  File "test", line 0 in <module>
  File "/python-dev/cpython/Lib/test/test_ast.py", line 559 in test_level_as_none
  File "/python-dev/cpython/Lib/unittest/case.py", line 600 in run
  File "/python-dev/cpython/Lib/unittest/case.py", line 648 in __call__
  File "/python-dev/cpython/Lib/unittest/suite.py", line 122 in run
  File "/python-dev/cpython/Lib/unittest/suite.py", line 84 in __call__
  File "/python-dev/cpython/Lib/unittest/suite.py", line 122 in run
  File "/python-dev/cpython/Lib/unittest/suite.py", line 84 in __call__
  File "/python-dev/cpython/Lib/unittest/suite.py", line 122 in run
  File "/python-dev/cpython/Lib/unittest/suite.py", line 84 in __call__
  File "/python-dev/cpython/Lib/test/support/__init__.py", line 1709 in run
  File "/python-dev/cpython/Lib/test/support/__init__.py", line 1810 in _run_suite
  File "/python-dev/cpython/Lib/test/support/__init__.py", line 1844 in run_unittest
  File "/python-dev/cpython/Lib/test/libregrtest/runtest.py", line 179 in test_runner
  File "/python-dev/cpython/Lib/test/libregrtest/runtest.py", line 180 in runtest_inner
  File "/python-dev/cpython/Lib/test/libregrtest/runtest.py", line 144 in runtest
  File "<string>", line 1 in <module>
  File "/python-dev/cpython/Lib/trace.py", line 469 in runctx
  File "/python-dev/cpython/Lib/test/libregrtest/main.py", line 330 in run_tests_sequential
  File "/python-dev/cpython/Lib/test/libregrtest/main.py", line 406 in run_tests
  File "/python-dev/cpython/Lib/test/libregrtest/main.py", line 466 in _main
  File "/python-dev/cpython/Lib/test/libregrtest/main.py", line 446 in main
  File "/python-dev/cpython/Lib/test/libregrtest/main.py", line 508 in main
  File "/python-dev/cpython/Lib/test/__main__.py", line 2 in <module>
  File "/python-dev/cpython/Lib/runpy.py", line 85 in _run_code
  File "/python-dev/cpython/Lib/runpy.py", line 184 in _run_module_as_main
Abort trap: 6
$ 

I applied the change you suggested, and this was the result:

$ ./python.exe -m test --coverage -D`pwd`/coverage_data test_ast
Run tests sequentially
0:00:00 [1/1] test_ast
1 test OK.
lines   cov%   module   (path)
  556     1%   _collections_abc   (/python-dev/cpython/Lib/_collections_abc.py)
  147    25%   _weakrefset   (/python-dev/cpython/Lib/_weakrefset.py)
   96    16%   abc   (/python-dev/cpython/Lib/abc.py)
  156    66%   ast   (/python-dev/cpython/Lib/ast.py)
  418     1%   codecs   (/python-dev/cpython/Lib/codecs.py)
  692     0%   collections.__init__   (/python-dev/cpython/Lib/collections/__init__.py)
  166     8%   contextlib   (/python-dev/cpython/Lib/contextlib.py)
  318    22%   dis   (/python-dev/cpython/Lib/dis.py)
   74     5%   genericpath   (/python-dev/cpython/Lib/genericpath.py)
  103     2%   importlib.__init__   (/python-dev/cpython/Lib/importlib/__init__.py)
 1776     0%   inspect   (/python-dev/cpython/Lib/inspect.py)
 1228     0%   locale   (/python-dev/cpython/Lib/locale.py)
  170     0%   multiprocessing.process   (/python-dev/cpython/Lib/multiprocessing/process.py)
  612     1%   os   (/python-dev/cpython/Lib/os.py)
  687     0%   platform   (/python-dev/cpython/Lib/platform.py)
  313     5%   posixpath   (/python-dev/cpython/Lib/posixpath.py)
  435     1%   sysconfig   (/python-dev/cpython/Lib/sysconfig.py)
  336     1%   test.libregrtest.main   (/python-dev/cpython/Lib/test/libregrtest/main.py)
  174    29%   test.libregrtest.runtest   (/python-dev/cpython/Lib/test/libregrtest/runtest.py)
  197    27%   test.libregrtest.save_env   (/python-dev/cpython/Lib/test/libregrtest/save_env.py)
 1341     3%   test.support.__init__   (/python-dev/cpython/Lib/test/support/__init__.py)
  870    98%   test.test_ast   (/python-dev/cpython/Lib/test/test_ast.py)
  461     0%   trace   (/python-dev/cpython/Lib/trace.py)
  285     2%   traceback   (/python-dev/cpython/Lib/traceback.py)
  824    20%   unittest.case   (/python-dev/cpython/Lib/unittest/case.py)
  329     8%   unittest.loader   (/python-dev/cpython/Lib/unittest/loader.py)
  134    20%   unittest.result   (/python-dev/cpython/Lib/unittest/result.py)
  222    44%   unittest.suite   (/python-dev/cpython/Lib/unittest/suite.py)
  134     0%   unittest.util   (/python-dev/cpython/Lib/unittest/util.py)
  384     6%   weakref   (/python-dev/cpython/Lib/weakref.py)
Total duration: 0:00:09
$
msg272988 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2016-08-17 21:19
New changeset 1bf307f42a6b by Ned Deily in branch 'default':
Issue #27594: Prevent assertion error when running test_ast with coverage
https://hg.python.org/cpython/rev/1bf307f42a6b
msg272992 - (view) Author: Ned Deily (ned.deily) * (Python committer) Date: 2016-08-17 21:24
Thanks for the report.  It looks the assert error is triggered by the new test case added in 59638baee25e for Issue13436.  Since that test case was only added for 3.6, I've only applied Ivan's suggested fix for 3.6 as well, although you could trigger the same assert in earlier releases.  Thanks, Ivan!
msg272994 - (view) Author: Ivan Levkivskyi (levkivskyi) * (Python committer) Date: 2016-08-17 21:34
Ned, thank you for applying the patch!

I have discovered this same issue accidentally while playing with possible implementations of PEP 526. It appeared as a failure in
test_sys_settrace in my fork.
History
Date User Action Args
2022-04-11 14:58:34adminsetgithub: 71781
2016-08-17 21:34:04levkivskyisetmessages: + msg272994
2016-08-17 21:24:31ned.deilysetstatus: open -> closed

nosy: + ned.deily
messages: + msg272992

resolution: fixed
stage: resolved
2016-08-17 21:19:05python-devsetnosy: + python-dev
messages: + msg272988
2016-08-16 14:24:08apsetmessages: + msg272859
2016-08-12 17:39:42Quentin.Pradetsetmessages: + msg272549
2016-08-12 11:54:59levkivskyisetnosy: + levkivskyi
messages: + msg272527
2016-08-03 10:45:35SilentGhostsetnosy: + SilentGhost
messages: + msg271891
2016-08-02 16:36:11Quentin.Pradetsetnosy: + Quentin.Pradet
2016-07-23 16:02:44brett.cannonsetnosy: + georg.brandl, benjamin.peterson
2016-07-22 22:32:06apcreate