Skip to content

Commit

Permalink
Merge pull request #9 from JWCook/tests
Browse files Browse the repository at this point in the history
This contribution greatly improves testing. Thanks to @JWCook for the good work!
  • Loading branch information
lsaffre authored Jul 23, 2024
2 parents 9d9bb30 + da3d529 commit f3fcf6a
Show file tree
Hide file tree
Showing 28 changed files with 370 additions and 816 deletions.
4 changes: 1 addition & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ jobs:
pip install -U pip setuptools
pip install -e .[dev]
- name: Run tests
run: pytest -v tests || diff tmp/ tests/docs1/expected && exit 1
# Remove this line once tests are updated to work in CI:
continue-on-error: true
run: pytest -vs tests

# For git tags, build and publish package to PyPI
publish:
Expand Down
5 changes: 5 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,11 @@ Run the test suite::

$ pytest

Generate an HTML test coverage report::

$ pytest --cov-report=html
$ python -m webbrowser test-reports/index.html

Release a new version to PyPI::

$ hatch version micro
Expand Down
13 changes: 13 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ dependencies = [
dev = [
"hatch",
"pytest",
"pytest-cov",
]

[project.urls]
Expand All @@ -65,3 +66,15 @@ only-include = ["sphinxfeed.py"]

[tool.hatch.build]
dev-mode-dirs = ["."]

# Coverage report config: by default, show condensed terminal output
[tool.coverage.run]
branch = true
source = ['.']
omit = ['tests/*', 'tasks.py']

[tool.coverage.html]
directory = 'test-reports'

[tool.pytest.ini_options]
addopts = "--cov --cov-report=term"
39 changes: 39 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
"""Pytest config for testing with SphinxTestApp
Notes on testing setup:
* A Sphinx test app is provided via `app` fixture from `sphinx.testing.fixtures`.
* The `sources` dir contains source files and config to use for tests
* Set via the `rootdir` fixture
* A subdirectory to use for a specific test can be set by a pytest marker:
* `@pytest.mark.sphinx("html", testroot="...")
* This subdirectory must contain a conf.py and source files
* The `outputs` dir contains expected output files
* Test build output is located under `/tmp/pytest*`
"""

import shutil
from pathlib import Path

import pytest

collect_ignore = ["sources", "outputs"]
pytest_plugins = "sphinx.testing.fixtures"

OUTPUT_DIR = Path(__file__).parent.resolve() / "outputs"
SOURCE_DIR = Path(__file__).parent.resolve() / "sources"


@pytest.fixture(scope="session")
def rootdir():
"""This fixture overrides the root directory used by SphinxTestApp. Also patches in a
Path.copytree() method for compatibility with sphinx.testing.path.path in older Sphinx versions.
"""

class PatchedPath(type(Path())):
def __new__(cls, *args):
return super().__new__(cls, *args)

def copytree(src, dest):
shutil.copytree(src, dest, symlinks=True)

yield PatchedPath(SOURCE_DIR)
Empty file removed tests/docs1/.static/dummy
Empty file.
220 changes: 0 additions & 220 deletions tests/docs1/conf.py

This file was deleted.

Loading

0 comments on commit f3fcf6a

Please sign in to comment.