From 65ae948eca116a104cb07831a81c92754bed2231 Mon Sep 17 00:00:00 2001 From: Adam Turner <9087854+AA-Turner@users.noreply.github.com> Date: Sat, 5 Feb 2022 14:57:09 +0000 Subject: [PATCH 1/3] Split out coverage --- .github/workflows/main.yml | 37 ++++++++++++++++++++++++++++++------- setup.py | 3 +-- tox.ini | 12 +----------- 3 files changed, 32 insertions(+), 20 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 1107089a6..071fdadba 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -18,13 +18,10 @@ jobs: docutils: du16 - python: "3.9" docutils: du17 - coverage: "--cov ./ --cov-append --cov-config setup.cfg" - python: "3.10" docutils: du18 - python: "3.11-dev" docutils: py311 - env: - PYTEST_ADDOPTS: ${{ matrix.coverage }} steps: - uses: actions/checkout@v3 @@ -43,12 +40,9 @@ jobs: - name: Install graphviz run: sudo apt-get install graphviz - name: Install dependencies - run: python -m pip install -U pip tox codecov + run: python -m pip install -U pip tox - name: Run Tox run: tox -e ${{ matrix.docutils }} -- -vv - - name: codecov - uses: codecov/codecov-action@v1 - if: matrix.coverage windows: runs-on: windows-2019 @@ -62,3 +56,32 @@ jobs: run: python -m pip install -U pip tox - name: Run Tox run: tox -e py -- -vv + + coverage: + # only run on pushes to branches in the sphinx-doc/sphinx repo + if: github.repository_owner == 'sphinx-doc' && github.event_name == 'push' + runs-on: ubuntu-latest + env: + PYTEST_ADDOPTS: "--cov ./ --cov-append --cov-config setup.cfg" + + steps: + - uses: actions/checkout@v3 + - name: Set up Python 3 + uses: actions/setup-python@v3 + with: + python-version: 3 + + - name: Check Python version + run: python --version + + - name: Install graphviz + run: sudo apt-get install graphviz + + - name: Install dependencies + run: python -m pip install -U tox pip codecov pytest-cov + + - name: Run Tox + run: tox -e py -- -vv + + - name: codecov + uses: codecov/codecov-action@v3 diff --git a/setup.py b/setup.py index e11a894c7..4ec215697 100644 --- a/setup.py +++ b/setup.py @@ -47,8 +47,7 @@ extras_require = { "types-requests", ], 'test': [ - 'pytest', - 'pytest-cov', + 'pytest>=4.6', 'html5lib', "typed_ast; python_version < '3.8'", 'cython', diff --git a/tox.ini b/tox.ini index 74e255bc1..105a02597 100644 --- a/tox.ini +++ b/tox.ini @@ -1,6 +1,6 @@ [tox] minversion = 2.4.0 -envlist = docs,flake8,mypy,twine,coverage,py{36,37,38,39,310},du{14,15,16,17,18} +envlist = docs,flake8,mypy,twine,py{36,37,38,39,310},du{14,15,16,17,18} [testenv] usedevelop = True @@ -58,16 +58,6 @@ extras = commands = isort --check-only --diff . -[testenv:coverage] -basepython = python3 -description = - Run code coverage checks. -setenv = - PYTEST_ADDOPTS = --cov sphinx --cov-config "{toxinidir}/setup.cfg" -commands = - {[testenv]commands} - coverage report - [testenv:mypy] basepython = python3 description = From cfa324a7edfd26ded71b2cb4d598ff51ba86b56a Mon Sep 17 00:00:00 2001 From: Adam Turner <9087854+AA-Turner@users.noreply.github.com> Date: Sun, 17 Apr 2022 18:34:52 +0100 Subject: [PATCH 2/3] Remove always-false branches --- sphinx/testing/fixtures.py | 10 ++-------- tests/test_ext_apidoc.py | 5 +---- tests/test_setup_command.py | 5 +---- 3 files changed, 4 insertions(+), 16 deletions(-) diff --git a/sphinx/testing/fixtures.py b/sphinx/testing/fixtures.py index 0b558e32c..939021fe1 100644 --- a/sphinx/testing/fixtures.py +++ b/sphinx/testing/fixtures.py @@ -64,10 +64,7 @@ def app_params(request: Any, test_params: Dict, shared_result: SharedResult, # ##### process pytest.mark.sphinx - if hasattr(request.node, 'iter_markers'): # pytest-3.6.0 or newer - markers = request.node.iter_markers("sphinx") - else: - markers = request.node.get_marker("sphinx") + markers = request.node.iter_markers("sphinx") pargs = {} kwargs: Dict[str, Any] = {} @@ -113,10 +110,7 @@ def test_params(request: Any) -> Dict: have same 'shared_result' value. **NOTE**: You can not specify both shared_result and srcdir. """ - if hasattr(request.node, 'get_closest_marker'): # pytest-3.6.0 or newer - env = request.node.get_closest_marker('test_params') - else: - env = request.node.get_marker('test_params') + env = request.node.get_closest_marker('test_params') kwargs = env.kwargs if env else {} result = { 'shared_result': None, diff --git a/tests/test_ext_apidoc.py b/tests/test_ext_apidoc.py index ee21f8ffd..411b1259b 100644 --- a/tests/test_ext_apidoc.py +++ b/tests/test_ext_apidoc.py @@ -22,10 +22,7 @@ def apidoc(rootdir, tempdir, apidoc_params): @pytest.fixture def apidoc_params(request): - if hasattr(request.node, 'iter_markers'): # pytest-3.6.0 or newer - markers = request.node.iter_markers("apidoc") - else: - markers = request.node.get_marker("apidoc") + markers = request.node.iter_markers("apidoc") pargs = {} kwargs = {} diff --git a/tests/test_setup_command.py b/tests/test_setup_command.py index a56f9d4a3..ef364676c 100644 --- a/tests/test_setup_command.py +++ b/tests/test_setup_command.py @@ -18,10 +18,7 @@ def setup_command(request, tempdir, rootdir): Run `setup.py build_sphinx` with args and kwargs, pass it to the test and clean up properly. """ - if hasattr(request.node, 'get_closest_marker'): # pytest-3.6.0 or newer - marker = request.node.get_closest_marker('setup_command') - else: - marker = request.node.get_marker('setup_command') + marker = request.node.get_closest_marker('setup_command') args = marker.args if marker else [] pkgrootdir = tempdir / 'test-setup' From f95bcf51efe2ec1ebf6a251322b37a6caf4e2aac Mon Sep 17 00:00:00 2001 From: Adam Turner <9087854+AA-Turner@users.noreply.github.com> Date: Fri, 22 Apr 2022 07:29:53 +0100 Subject: [PATCH 3/3] Refactor --- sphinx/testing/fixtures.py | 12 +++++------- tests/test_ext_apidoc.py | 10 ++++------ 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/sphinx/testing/fixtures.py b/sphinx/testing/fixtures.py index 939021fe1..891f0f7cc 100644 --- a/sphinx/testing/fixtures.py +++ b/sphinx/testing/fixtures.py @@ -64,16 +64,14 @@ def app_params(request: Any, test_params: Dict, shared_result: SharedResult, # ##### process pytest.mark.sphinx - markers = request.node.iter_markers("sphinx") pargs = {} kwargs: Dict[str, Any] = {} - if markers is not None: - # to avoid stacking positional args - for info in reversed(list(markers)): - for i, a in enumerate(info.args): - pargs[i] = a - kwargs.update(info.kwargs) + # to avoid stacking positional args + for info in reversed(list(request.node.iter_markers("sphinx"))): + for i, a in enumerate(info.args): + pargs[i] = a + kwargs.update(info.kwargs) args = [pargs[i] for i in sorted(pargs.keys())] diff --git a/tests/test_ext_apidoc.py b/tests/test_ext_apidoc.py index 411b1259b..2d427417b 100644 --- a/tests/test_ext_apidoc.py +++ b/tests/test_ext_apidoc.py @@ -22,15 +22,13 @@ def apidoc(rootdir, tempdir, apidoc_params): @pytest.fixture def apidoc_params(request): - markers = request.node.iter_markers("apidoc") pargs = {} kwargs = {} - if markers is not None: - for info in reversed(list(markers)): - for i, a in enumerate(info.args): - pargs[i] = a - kwargs.update(info.kwargs) + for info in reversed(list(request.node.iter_markers("apidoc"))): + for i, a in enumerate(info.args): + pargs[i] = a + kwargs.update(info.kwargs) args = [pargs[i] for i in sorted(pargs.keys())] return args, kwargs