pytest-dev / pytest-cov

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

Silent fail with returncode 1 when using Python 3.11 #564

Open carmenbianca opened 1 year ago

carmenbianca commented 1 year ago

Summary

When using pytest-cov using Python 3.11, pytest quietly fails with returncode 1.

Expected vs actual result

Expected: pytest --cov=module works.

Actual result: pytest --cov=module silently fails.

$ poetry run pytest -v --cov=reuse
$ echo $?
1

Reproducer

Versions

Output of relevant packages pip list, python --version, pytest --version etc.

$ pip list
Package                       Version
----------------------------- ---------
alabaster                     0.7.12
astroid                       2.11.7
attrs                         22.1.0
Babel                         2.10.3
binaryornot                   0.4.4
black                         22.8.0
boolean.py                    4.0
bump2version                  1.0.1
certifi                       2022.9.24
cfgv                          3.3.1
chardet                       5.0.0
charset-normalizer            2.0.12
click                         8.0.4
commonmark                    0.9.1
coverage                      6.2
dill                          0.3.4
distlib                       0.3.6
docutils                      0.17.1
filelock                      3.4.1
identify                      2.4.4
idna                          3.4
imagesize                     1.4.1
iniconfig                     1.1.1
isort                         5.10.1
Jinja2                        3.0.3
lazy-object-proxy             1.7.1
license-expression            30.0.0
MarkupSafe                    2.0.1
mccabe                        0.7.0
mypy-extensions               0.4.3
nodeenv                       1.6.0
packaging                     21.3
pathspec                      0.9.0
pbr                           5.10.0
pip                           21.3.1
platformdirs                  2.4.0
pluggy                        1.0.0
pre-commit                    2.17.0
py                            1.11.0
Pygments                      2.13.0
pylint                        2.13.9
pyparsing                     3.0.7
pytest                        7.0.1
pytest-cov                    4.0.0
python-debian                 0.1.44
pytz                          2022.4
PyYAML                        6.0
recommonmark                  0.7.1
requests                      2.27.1
reuse                         1.0.0
setuptools                    59.6.0
snowballstemmer               2.2.0
Sphinx                        5.2.3
sphinx-autodoc-typehints      1.12.0
sphinx-rtd-theme              1.0.0
sphinxcontrib-apidoc          0.3.0
sphinxcontrib-applehelp       1.0.2
sphinxcontrib-devhelp         1.0.2
sphinxcontrib-htmlhelp        2.0.0
sphinxcontrib-jsmath          1.0.1
sphinxcontrib-qthelp          1.0.3
sphinxcontrib-serializinghtml 1.1.5
toml                          0.10.2
tomli                         1.2.3
urllib3                       1.26.12
virtualenv                    20.16.2
wrapt                         1.14.1
$ python --version
Python 3.11.0rc2
$ pytest --version
pytest 7.0.1

Config

Include your tox.ini, pytest.ini, .coveragerc, setup.cfg or any relevant configuration.

$ cat pyproject.toml
# SPDX-FileCopyrightText: 2018 Free Software Foundation Europe e.V. <https://fsfe.org>
# SPDX-FileCopyrightText: 2022 Alliander N.V. <https://www.alliander.com>
# SPDX-FileCopyrightText: 2022 Carmen Bianca Bakker <carmenbianca@fsfe.org>
#
# SPDX-License-Identifier: GPL-3.0-or-later

[tool.poetry]
name = "reuse"
version = "1.0.0"
description = "reuse is a tool for compliance with the REUSE recommendations."
authors = [
    "Free Software Foundation Europe <contact@fsfe.org>",
]
maintainers = [
    "Carmen Bianca Bakker <carmenbianca@fsfe.org>",
]
license = "Apache-2.0 AND CC0-1.0 AND GPL-3.0-or-later"
readme = "README.md"

packages = [
    { include = "reuse", from = "src" }
]
include = [
    { path = "tests", format = "sdist" },
    { path = "po", format = "sdist" },
    { path = "src/reuse/locale/**/*.mo", format="wheel" },
    { path = "AUTHORS.rst" },
    { path = "README.md" },
    { path = "CHANGELOG.md" },
    { path = ".reuse" },
    { path = "LICENSES" },
]

homepage = "https://reuse.software/"
repository = "https://github.com/fsfe/reuse-tool"
documentation = "https://reuse.readthedocs.org/"

classifiers = [
    "Development Status :: 5 - Production/Stable",
    "Intended Audience :: Developers",
]

[tool.poetry.dependencies]
python = "^3.6.2"
Jinja2 = "^3.0.0"
binaryornot = "^0.4.4"
"boolean.py" = ">=3.8"
license-expression = ">=1.0"
python-debian = "^0.1.38,!=0.1.45,!=0.1.46,!=0.1.47"
setuptools = "*"

[tool.poetry.dev-dependencies]
Sphinx = ">=4.0.0"
recommonmark = "^0.7.1"
sphinx-autodoc-typehints = "^1.12.0"
sphinx-rtd-theme = "^1.0.0"
sphinxcontrib-apidoc = "^0.3.0"
black = ">=20"
isort = "^5.6.0"
bump2version = "^1.0.0"
pre-commit = "^2.9.0"
pylint = "^2.12.2"
pytest = ">=6.0.0"
pytest-cov = ">=2.10.0"

[tool.poetry.scripts]
reuse = 'reuse._main:main'

[tool.poetry.build]
generate-setup-file = false
script = "build.py"

[build-system]
requires = ["poetry-core>=1.1.0", "setuptools"]
build-backend = "poetry.core.masonry.api"

[tool.black]
line-length = 80

[tool.isort]
multi_line_output = 3
include_trailing_comma = true
force_grid_wrap = 0
use_parentheses = true
line_length = 80

Code

Link to your repository, gist, pastebin or just paste raw code that illustrates the issue.

Can be reproduced on this commit: https://github.com/fsfe/reuse-tool/pull/600/commits/1248c125cb90ea599040c129fbe2e89a09f72ec7

Steps to reproduce:

# In a Python 3.11 venv
$ poetry install
$ poetry run pytest --cov=reuse
cancan101 commented 1 year ago

Is there any workaround here to get pytest to work on 3.11? We are running into the same issue.

carmenbianca commented 1 year ago

Not that I'm aware of.

RonnyPfannschmidt commented 1 year ago

Does it work outside of poetry run?

cancan101 commented 1 year ago

I am not using poetry but I'm having this issue.

RonnyPfannschmidt commented 1 year ago

What commands do you use and do you have a example reproducer?

carmenbianca commented 1 year ago

poetry run in my example is optional. You can run pytest without poetry run just the same, and the result is the same.

cancan101 commented 1 year ago

This seems to be the problematic line of code: https://github.com/pytest-dev/pytest-cov/blob/f7fced579e36b72b57e14768026467e4c4511a40/src/pytest_cov/engine.py#L234

cancan101 commented 1 year ago

It looks like you need coverage>=6.3 to fix this issue.