Skip to main content

PyPI Travis

Decorate your pytest suite with RSpec-inspired markers describe, context and it. Then run pytest --it to see a plaintext, org-mode compatible spec of the test structure.

img/output-example.png

Install

pytest-it is available on PyPi: pip install pytest-it.

Examples

A basic example that uses pytest.mark.describe, pytest.mark.context and pytest.mark.it:

from pytest import mark as m

@m.describe("The test function report format")
class TestPytestItExample(object):

    @m.context("When @pytest.mark.it is used")
    @m.it("Displays an '- It: ' block matching the decorator")
    def test_it_decorator(self, testdir):
        pass

This produces:

- Describe: The test function report format...

  - Context: When @pytest.mark.it is used...
    - ✓ It: Displays an '- It: ' block matching the decorator

Describe and Context blocks can be nested arbitrarily by using multiple markers, eg:

from pytest import mark as m

@m.describe("The test function report format")
class TestPytestItExample(object):

    @m.context("When @pytest.mark.it is not used")
    @m.it("Displays the test function name")
    def test_no_argument(self, testdir):
        pass

    @m.context("When @pytest.mark.it is not used")
    @m.context("but the test name starts with 'test_it_'")
    @m.it("Prettifies the test name into the 'It: ' value")
    def test_populates_the_it_marker_using_function_name(self, testdir):
        pass

This produces:

- Describe: The test function report format...

  - Context: When @pytest.mark.it is not used...
    - ✓ It: Displays the test function name

    - ...but the test name starts with 'test_it_'...
      - ✓ It: Prettifies the test name into the 'It: ' value

Behaviour

  • Pytest markers are used to specify the Describe:, Context: and It: sections. You can set these in all the usual ways that you specify pytest markers.

  • Describe and Context can be nested arbitrarily.

  • If --collect-only is used, it displays the same pytest-it spec as usual, but without the test result (✓/F/s).

  • If -v is higher than 0, the full path to the test function is include in the test name.

  • If pytest.mark.it is not used on a test, the test name is displayed instead of the It: does something output.

  • If pytest.mark.it is not used but the test name starts with test_it, pytest-it will prettify the test name into an It: does something value.

  • The test output should be able to be copied directly into an org-mode file.

Background

Pytest provides a lot of useful features for testing in Python, but when testing complex systems, it can be hard to clearly communicate the intent of a test using the standard test_module.py::TestClass::test_function structure.

One way to improve clarity is to use a BDD testing framework (eg. Behave, Mamba, Rspec), but it’s not always desirable to restructure existing test and program code.

There are some pytest plugins that attempt to bridge this gap, by providing alternative ways to structure the tests (eg. pytest-describe, pytest-bdd), or altering the test report output (eg. pytest-testdox, pytest-pspec).

pytest-it takes a similar approach to pytest-testdox, by providing pytest markers that can describe the test output. pytest-it supports a few other features, such as:

  • A plaintext test structure that can easily be copied to markdown/org-mode documents.

  • Arbitrary nesting of describe and context markers.

  • Supporting the --collect-only pytest flag to display test structure.

  • Displaying the full path to each test if -v is used.

  • Neatly integrating tests in the output if they don’t use the pytest-it markers.

Although pytest-it does not change the behaviour of pytest tests, you may find it a useful tool for thinking about test structure, and communicating the intention of both the test code and the system under test.

Metadata

Release files for pytest-it 0.1.5

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

Source distribution (sdist)

Source distribution for pytest-it 0.1.5
File Size Uploaded Provenance
pytest-it-0.1.5.tar.gz 9.6 kB Without provenance Details

Release files / pytest-it-0.1.5.tar.gz

Download URL pytest-it-0.1.5.tar.gz
Size 9.6 kB
Tags Source
SHA-256 checksum
How to use checksums
d2d21e9dd371a423b357e955ebe4afd5cd848508e448e6476f21eb034733e2f1
BLAKE2b-256 checksum
How to use checksums
4336e0d0efe8b75b7a2ce4f10f3b0bce57d8ed03d6b44972c96b32095fbf58cf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.6

Security for pytest-it 0.1.5

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

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