Skip to main content

Sphinxtesters - utilities for testing Sphinx extensions

Quickstart

If you have a directory containing a sphinx project, test that it builds with something like:

class TestMyProject(SourcesBuilder):

    page_source_template = 'path/to/sphinx_dir'

    def test_basic_build(self):
        # Get doctree for page "a_page.rst"
        doctree = self.get_doctree('a_page')
        # Assert stuff about doctree version of page
        html = self.get_built_file('a_page.html')
        # Assert stuff about html version of page

You can try adding other page content by using the rst_sources dictionary:

class TestChangedProject(SourcesBuilder):

    page_source_template = 'path/to/sphinx_dir'
    rst_sources = {'a_page': """Replacement text for page""",
                   'b_page': """An entirely new page"""}

    def test_basic_build(self):
        a_doctree = self.get_doctree('a_page')
        b_doctree = self.get_doctree('b_page')
        # Your tests for the new page content here

Set the text of the conf.py file with the conf_source attribute:

class TestConfeddProject(SourcesBuilder):

    page_source_template = 'path/to/sphinx_dir'
    rst_sources = {'a_page': """Replacement text for page""",
                   'b_page': """An entirely new page"""}
    conf_source = """ # This overwrites existing conf.py """

    def test_basic_build(self):
        a_doctree = self.get_doctree('a_page')
        b_doctree = self.get_doctree('b_page')
        # Your tests for the new page content here

You don’t need to set page_source_template; if you don’t, you start with a fresh project, where the only pages are the ones you specify in rst_sources.

class TestFreshProject(SourcesBuilder):

    rst_sources = {'a_page': """A new page""",
                   'b_page': """Another new page"""}
    conf_source = """ # Stuff for the conf.py file """

    def test_basic_build(self):
        a_doctree = self.get_doctree('a_page')
        b_doctree = self.get_doctree('b_page')
        # Your tests for the new page content here

See the tests for examples of using Sphinxtesters for testing builds of Sphinx projects.

Installation

pip install sphinxtesters

Code

See https://github.com/matthew-brett/sphinxtesters

Released under the BSD two-clause license - see the file LICENSE in the source distribution.

travis-ci kindly tests the code automatically under Python versions 2.7, and 3.3 through 3.6.

The latest released version is at https://pypi.python.org/pypi/sphinxtesters

Tests

  • Install sphinxtesters

  • Install the pytest testing framework:

    pip install pytest
  • Run the tests with:

    pytest sphinxtesters

Support

Please put up issues on the sphinxtesters issue tracker.

Release files for sphinxtesters 0.2.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for sphinxtesters 0.2.4
File Size Uploaded
sphinxtesters-0.2.4.tar.gz 11.4 kB Details

Release files / sphinxtesters-0.2.4.tar.gz

Download URL sphinxtesters-0.2.4.tar.gz
Size 11.4 kB
Tags Source
SHA-256 checksum
How to use checksums
09c456e1cd61ec99b64851e2990d2152fdf05bb53d87f3b294f22d73f939d6ca
BLAKE2b-256 checksum
How to use checksums
aa0893af63fc5c6fd4c66b84a92c0048c5d2134fd168c6d763b01a476a3496f1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.12.7

Release history Release notifications | RSS feed

This release

0.2.4 This release

1 release file

0.2.3

1 release file

0.2.2

1 release file

0.2.1

1 release file

0.2

1 release file

0.1.1

1 release file

0.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page