Skip to content

Commit

Permalink
fix: make this work on CPython 3.11 #1241
Browse files Browse the repository at this point in the history
The fix for CTracer is egregious and will need to be updated when there's a
supported way to do it.

The fullcoverage skip is noted in
#1278

The raise_through_with skip is noted in
#1270
  • Loading branch information
nedbat committed Nov 10, 2021
1 parent dfa9774 commit 91e4640
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 2 deletions.
1 change: 1 addition & 0 deletions .github/workflows/coverage.yml
Expand Up @@ -38,6 +38,7 @@ jobs:
- "3.8"
- "3.9"
- "3.10"
- "3.11.0-alpha.2"
- "pypy3"
exclude:
# Windows PyPy doesn't seem to work?
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/testsuite.yml
Expand Up @@ -37,6 +37,7 @@ jobs:
- "3.8"
- "3.9"
- "3.10"
- "3.11.0-alpha.2"
- "pypy3"
exclude:
# Windows PyPy doesn't seem to work?
Expand Down
8 changes: 7 additions & 1 deletion coverage/ctracer/util.h
Expand Up @@ -12,9 +12,15 @@
#undef COLLECT_STATS /* Collect counters: stats are printed when tracer is stopped. */
#undef DO_NOTHING /* Define this to make the tracer do nothing. */

#if PY_VERSION_HEX >= 0x030B00A0
// 3.11 moved f_lasti into an internal structure. This is totally the wrong way
// to make this work, but it's all I've got until https://bugs.python.org/issue40421
// is resolved.
#include <internal/pycore_frame.h>
#define MyFrame_lasti(f) ((f)->f_frame->f_lasti * 2)
#elif PY_VERSION_HEX >= 0x030A00A7
// The f_lasti field changed meaning in 3.10.0a7. It had been bytes, but
// now is instructions, so we need to adjust it to use it as a byte index.
#if PY_VERSION_HEX >= 0x030A00A7
#define MyFrame_lasti(f) ((f)->f_lasti * 2)
#else
#define MyFrame_lasti(f) ((f)->f_lasti)
Expand Down
1 change: 1 addition & 0 deletions setup.py
Expand Up @@ -44,6 +44,7 @@ def better_set_verbosity(v):
Programming Language :: Python :: 3.8
Programming Language :: Python :: 3.9
Programming Language :: Python :: 3.10
Programming Language :: Python :: 3.11
Programming Language :: Python :: Implementation :: CPython
Programming Language :: Python :: Implementation :: PyPy
Topic :: Software Development :: Quality Assurance
Expand Down
2 changes: 2 additions & 0 deletions tests/test_arcs.py
Expand Up @@ -279,6 +279,8 @@ def test_continue_through_with(self):
arcz=arcz,
)

@pytest.mark.skipif(env.PYVERSION[:2] >= (3, 11), reason="avoid a 3.11 bug: 45709")
# https://github.com/nedbat/coveragepy/issues/1270
def test_raise_through_with(self):
if env.PYBEHAVIOR.exit_through_with:
arcz = ".1 12 27 78 8. 9A A. -23 34 45 53 6-2"
Expand Down
2 changes: 2 additions & 0 deletions tests/test_process.py
Expand Up @@ -748,6 +748,8 @@ def f():
@pytest.mark.expensive
@pytest.mark.skipif(env.METACOV, reason="Can't test fullcoverage when measuring ourselves")
@pytest.mark.skipif(not env.C_TRACER, reason="fullcoverage only works with the C tracer.")
@pytest.mark.skipif(env.PYVERSION[:2] >= (3, 11), reason="this test needs work on 3.11")
# https://github.com/nedbat/coveragepy/issues/1278
def test_fullcoverage(self):
# fullcoverage is a trick to get stdlib modules measured from
# the very beginning of the process. Here we import os and
Expand Down
3 changes: 2 additions & 1 deletion tox.ini
Expand Up @@ -3,7 +3,7 @@

[tox]
# When changing this list, be sure to check the [gh-actions] list below.
envlist = py{36,37,38,39,310}, pypy3, doc, lint
envlist = py{36,37,38,39,310,311}, pypy3, doc, lint
skip_missing_interpreters = {env:COVERAGE_SKIP_MISSING_INTERPRETERS:True}
toxworkdir = {env:TOXWORKDIR:.tox}

Expand Down Expand Up @@ -95,4 +95,5 @@ python =
3.8: py38
3.9: py39
3.10: py310
3.11: py311
pypy3: pypy3

0 comments on commit 91e4640

Please sign in to comment.