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

Python 3.12.0b1/2 Missing Coverage for Exiting a Conditional in a Finally Block #1640

Closed
rmartin16 opened this issue Jun 11, 2023 · 1 comment
Labels
bug Something isn't working cpython Reported as a bug in CPython

Comments

@rmartin16
Copy link

rmartin16 commented Jun 11, 2023

Describe the bug
Covered branch for exiting from a conditional in a finally block is being reported uncovered in Python 3.12.0 beta 1 and beta 2.

To Reproduce
How can we reproduce the problem? Please be specific. Don't link to a failing CI job. Answer the questions below:

  1. What version of Python are you using?
  • 3.12.0b1 and 3.12.0b2
  1. What version of coverage.py shows the problem? The output of coverage debug sys is helpful.
  • All of my testing was with coverage==7.2.7 but this problem also occurs for master.
coverage debug sys
~/github/beeware via 🐍 v3.12.0b2+ (venv-3.12-briefcase) took 2s 
❯ coverage debug sys
-- sys -------------------------------------------------------
               coverage_version: 7.2.7
                coverage_module: /home/russell/github/beeware/briefcase/venv-3.12-briefcase/lib/python3.12/site-packages/coverage/__init__.py
                         tracer: -none-
                        CTracer: available
           plugins.file_tracers: -none-
            plugins.configurers: -none-
      plugins.context_switchers: -none-
              configs_attempted: .coveragerc
                                 setup.cfg
                                 tox.ini
                                 pyproject.toml
                   configs_read: -none-
                    config_file: None
                config_contents: -none-
                      data_file: -none-
                         python: 3.12.0b2+ (heads/3.12:8c4cf96a06, Jun 10 2023, 14:09:05) [GCC 11.3.0]
                       platform: Linux-6.2.6-76060206-generic-x86_64-with-glibc2.35
                 implementation: CPython
                     executable: /home/russell/github/beeware/briefcase/venv-3.12-briefcase/bin/python
                   def_encoding: utf-8
                    fs_encoding: utf-8
                            pid: 1331663
                            cwd: /home/russell/github/beeware
                           path: /home/russell/github/beeware/briefcase/venv-3.12-briefcase/bin
                                 /home/russell/.pyenv/versions/3.12-dev/lib/python312.zip
                                 /home/russell/.pyenv/versions/3.12-dev/lib/python3.12
                                 /home/russell/.pyenv/versions/3.12-dev/lib/python3.12/lib-dynload
                                 /home/russell/github/beeware/briefcase/venv-3.12-briefcase/lib/python3.12/site-packages
                                 /home/russell/github/beeware/briefcase/src
                    environment: CONDA_PYTHON_EXE = /home/russell/anaconda3/bin/python
                                 HOME = /home/russell
                                 PYENV_ROOT = /home/russell/.pyenv
                                 PYENV_SHELL = bash
                                 PYENV_VIRTUALENV_INIT = 1
                                 PYTHONDEVMODE = 1
                   command_line: /home/russell/github/beeware/briefcase/venv-3.12-briefcase/bin/coverage debug sys
         sqlite3_sqlite_version: 3.37.2
             sqlite3_temp_store: 0
        sqlite3_compile_options: ATOMIC_INTRINSICS=1, COMPILER=gcc-11.3.0, DEFAULT_AUTOVACUUM,
                                 DEFAULT_CACHE_SIZE=-2000, DEFAULT_FILE_FORMAT=4,
                                 DEFAULT_JOURNAL_SIZE_LIMIT=-1, DEFAULT_MMAP_SIZE=0, DEFAULT_PAGE_SIZE=4096,
                                 DEFAULT_PCACHE_INITSZ=20, DEFAULT_RECURSIVE_TRIGGERS,
                                 DEFAULT_SECTOR_SIZE=4096, DEFAULT_SYNCHRONOUS=2,
                                 DEFAULT_WAL_AUTOCHECKPOINT=1000, DEFAULT_WAL_SYNCHRONOUS=2,
                                 DEFAULT_WORKER_THREADS=0, ENABLE_COLUMN_METADATA, ENABLE_DBSTAT_VTAB,
                                 ENABLE_FTS3, ENABLE_FTS3_PARENTHESIS, ENABLE_FTS3_TOKENIZER, ENABLE_FTS4,
                                 ENABLE_FTS5, ENABLE_JSON1, ENABLE_LOAD_EXTENSION, ENABLE_MATH_FUNCTIONS,
                                 ENABLE_PREUPDATE_HOOK, ENABLE_RTREE, ENABLE_SESSION, ENABLE_STMTVTAB,
                                 ENABLE_UNLOCK_NOTIFY, ENABLE_UPDATE_DELETE_LIMIT, HAVE_ISNAN,
                                 LIKE_DOESNT_MATCH_BLOBS, MALLOC_SOFT_LIMIT=1024, MAX_ATTACHED=10,
                                 MAX_COLUMN=2000, MAX_COMPOUND_SELECT=500, MAX_DEFAULT_PAGE_SIZE=32768,
                                 MAX_EXPR_DEPTH=1000, MAX_FUNCTION_ARG=127, MAX_LENGTH=1000000000,
                                 MAX_LIKE_PATTERN_LENGTH=50000, MAX_MMAP_SIZE=0x7fff0000,
                                 MAX_PAGE_COUNT=1073741823, MAX_PAGE_SIZE=65536, MAX_SCHEMA_RETRY=25,
                                 MAX_SQL_LENGTH=1000000000, MAX_TRIGGER_DEPTH=1000,
                                 MAX_VARIABLE_NUMBER=250000, MAX_VDBE_OP=250000000, MAX_WORKER_THREADS=8,
                                 MUTEX_PTHREADS, OMIT_LOOKASIDE, SECURE_DELETE, SOUNDEX, SYSTEM_MALLOC,
                                 TEMP_STORE=1, THREADSAFE=1, USE_URI

  1. What versions of what packages do you have installed? The output of pip freeze is helpful.
pip freeze
❯ pip freeze
arrow==1.2.3
binaryornot==0.4.4
-e git+https://github.com/beeware/briefcase.git@b62e9c91a85dcbf681c349df642d4fc3438e0c9c#egg=briefcase
build==0.10.0
cachetools==5.3.1
certifi==2023.5.7
cfgv==3.3.1
chardet==5.1.0
charset-normalizer==3.1.0
click==8.1.3
colorama==0.4.6
cookiecutter==2.1.1
coverage==7.2.7
coverage-conditional-plugin==0.9.0
distlib==0.3.6
execnet==1.9.0
filelock==3.12.1
gitdb==4.0.10
GitPython==3.1.31
identify==2.5.24
idna==3.4
iniconfig==2.0.0
Jinja2==3.1.2
jinja2-time==0.2.0
markdown-it-py==2.2.0
MarkupSafe==2.1.3
mdurl==0.1.2
nodeenv==1.8.0
packaging==23.1
pipdeptree==2.9.0
platformdirs==3.5.3
pluggy==1.0.0
pre-commit==3.3.2
psutil==5.9.5
Pygments==2.15.1
pyproject_api==1.5.1
pyproject_hooks==1.0.0
pytest==7.3.2
pytest-xdist==3.3.1
python-dateutil==2.8.2
python-slugify==8.0.1
PyYAML==6.0
requests==2.31.0
rich==13.4.1
setuptools-scm==7.1.0
six==1.16.0
smmap==5.0.0
text-unidecode==1.3
tomli_w==1.0.0
tox==4.6.0
typing_extensions==4.6.3
urllib3==2.0.3
virtualenv==20.23.0
  1. What code shows the problem? Give us a specific commit of a specific repo that we can check out. If you've already worked around the problem, please provide a commit before that fix.
import pytest


def example(raise_exc: bool, enter_finally_cond: bool):
    try:
        if raise_exc:
            print("raising exception")
            raise Exception
        print("not raising exception")
    finally:
        if enter_finally_cond:
            print("in finally conditional")

    print("after finally")


@pytest.mark.parametrize("enter_finally_cond", (True, False))
def test_example_success(enter_finally_cond):
    example(raise_exc=False, enter_finally_cond=enter_finally_cond)


@pytest.mark.parametrize("enter_finally_cond", (True, False))
def test_example_fails(enter_finally_cond):
    with pytest.raises(Exception):
        example(raise_exc=True, enter_finally_cond=enter_finally_cond)
  1. What commands should we run to reproduce the problem? Be specific. Include everything, even git clone, pip install, and so on. Explain like we're five!
  • Run coverage run --branch -m pytest test.py && coverage report -m for the sample code above in a file named test.py.

Expected behavior
This example code should be 100% covered on Python 3.12 as on Python 3.11.

Additional Information

Example Runs
./briefcase/venv-3.11-briefcase/bin/python -m coverage run --branch -m pytest test.py && coverage report -m
=================================== test session starts ====================================
platform linux -- Python 3.11.3, pytest-7.4.0.dev127+g52cf700f, pluggy-1.0.0
rootdir: /home/russell/github/beeware
plugins: xdist-3.3.1
collected 4 items                                                                          

test.py ....                                                                         [100%]

==================================== 4 passed in 0.01s =====================================
Name      Stmts   Miss Branch BrPart  Cover   Missing
-----------------------------------------------------
test.py      17      0     13      0   100%
-----------------------------------------------------
TOTAL        17      0     13      0   100%./briefcase/venv-3.12.0b1-briefcase/bin/python -m coverage run --branch -m pytest test.py && coverage report -m
=================================== test session starts ====================================
platform linux -- Python 3.12.0b1, pytest-7.3.1, pluggy-1.0.0
rootdir: /home/russell/github/beeware
plugins: xdist-3.3.1
collected 4 items                                                                          

test.py ....                                                                         [100%]

==================================== 4 passed in 0.02s =====================================
Name      Stmts   Miss Branch BrPart  Cover   Missing
-----------------------------------------------------
test.py      17      0     13      1    97%   12->exit
-----------------------------------------------------
TOTAL        17      0     13      1    97%./briefcase/venv-3.12-briefcase/bin/python -m coverage run --branch -m pytest test.py && coverage report -m
=================================== test session starts ====================================
platform linux -- Python 3.12.0b2+, pytest-7.3.2, pluggy-1.0.0
rootdir: /home/russell/github/beeware
plugins: xdist-3.3.1
collected 4 items                                                                          

test.py ....                                                                         [100%]

==================================== 4 passed in 0.02s =====================================
Name      Stmts   Miss Branch BrPart  Cover   Missing
-----------------------------------------------------
test.py      17      0     13      1    97%   12->exit
-----------------------------------------------------
TOTAL        17      0     13      1    97%
@nedbat
Copy link
Owner

nedbat commented Jun 11, 2023

Thanks, I've reported this as a bug against 3.12: python/cpython#105658

@nedbat nedbat added cpython Reported as a bug in CPython and removed needs triage labels Jun 11, 2023
@nedbat nedbat closed this as not planned Won't fix, can't repro, duplicate, stale Jun 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working cpython Reported as a bug in CPython
Projects
None yet
Development

No branches or pull requests

2 participants