A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://pypi.python.org/pypi/pytest-it below:

pytest-it·PyPI

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.

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 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:

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.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4