Treat Python warnings as errors during testing

This commit is contained in:
Adam Turner 2023-02-01 11:15:05 +00:00
parent a502e75233
commit c17300aa7a
6 changed files with 21 additions and 6 deletions

View File

@ -36,7 +36,7 @@ jobs:
env:
PYTHONDEVMODE: "1" # -X dev
PYTHONWARNDEFAULTENCODING: "1" # -X warn_default_encoding
PYTHONWARNINGS: "always" # -W always
PYTHONWARNINGS: "error,always:unclosed:ResourceWarning"
PYTEST_ADDOPTS: "--cov ./ --cov-append --cov-config pyproject.toml"
VIRTUALENV_SYSTEM_SITE_PACKAGES: "1"

View File

@ -13,7 +13,7 @@ env:
FORCE_COLOR: "1"
PYTHONDEVMODE: "1" # -X dev
PYTHONWARNDEFAULTENCODING: "1" # -X warn_default_encoding
PYTHONWARNINGS: "always" # -W always
PYTHONWARNINGS: "error,always:unclosed:ResourceWarning"
jobs:
ubuntu:
@ -44,6 +44,8 @@ jobs:
if: "endsWith(matrix.python, '-dev')"
with:
python-version: ${{ matrix.python }}
env:
PYTHONWARNINGS: ""
- name: Check Python version
run: python --version
- name: Install graphviz
@ -52,6 +54,8 @@ jobs:
run: |
python -m pip install --upgrade pip
python -m pip install .[test]
env:
PYTHONWARNINGS: ""
- name: Install Docutils ${{ matrix.docutils }}
run: python -m pip install --upgrade "docutils==${{ matrix.docutils }}.*"
- name: Test with pytest
@ -71,6 +75,8 @@ jobs:
run: |
python -m pip install --upgrade pip
python -m pip install .[test]
env:
PYTHONWARNINGS: ""
- name: Test with pytest
run: python -m pytest -vv --durations 25
@ -92,7 +98,11 @@ jobs:
run: |
python -m pip install --upgrade pip
python -m pip install .[test]
env:
PYTHONWARNINGS: ""
- name: Install Docutils' HEAD
run: python -m pip install git+https://repo.or.cz/docutils.git\#subdirectory=docutils
env:
PYTHONWARNINGS: ""
- name: Test with pytest
run: python -m pytest -vv

View File

@ -181,7 +181,7 @@ of targets and allows testing against multiple different Python environments:
* To run unit tests for a specific Python version and turn on deprecation
warnings so they're shown in the test output::
PYTHONWARNINGS=all tox -e py310
PYTHONWARNINGS=error tox -e py310
* Arguments to ``pytest`` can be passed via ``tox``, e.g., in order to run a
particular test::

View File

@ -3,8 +3,13 @@
import sys
from unittest import TestCase
import pytest
from sphinx.deprecation import RemovedInSphinx70Warning
from sphinx.ext.napoleon.iterators import modify_iter, peek_iter
with pytest.warns(DeprecationWarning,
match="sphinx.ext.napoleon.iterators is deprecated."):
from sphinx.ext.napoleon.iterators import modify_iter, peek_iter
class ModuleIsDeprecatedTest(TestCase):

View File

@ -33,7 +33,7 @@ def setup_command(request, tempdir, rootdir):
proc = subprocess.Popen(
command,
env=dict(os.environ, PYTHONPATH=pythonpath),
env=dict(os.environ, PYTHONPATH=pythonpath, PYTHONWARNINGS='default'),
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
yield namedtuple('setup', 'pkgroot,proc')(pkgrootdir, proc)

View File

@ -21,7 +21,7 @@ description =
extras =
test
setenv =
PYTHONWARNINGS = all
PYTHONWARNINGS = error
PYTEST_ADDOPTS = {env:PYTEST_ADDOPTS:} --color yes
commands=
python -X dev -X warn_default_encoding -m pytest --durations 25 {posargs}