All Projects → mattduck → pytest-it

mattduck / pytest-it

Licence: MIT License
Decorate your pytest suite with RSpec-style pytest markers, then run `pytest --it` to see a plaintext spec of the test structure.

Programming Languages

python
139335 projects - #7 most used programming language
Makefile
30231 projects

Projects that are alternatives of or similar to pytest-it

Aruba
Test command-line applications with Cucumber-Ruby, RSpec or Minitest. The most up to date documentation can be found on Cucumber.Pro (https://app.cucumber.pro/projects/aruba)
Stars: ✭ 900 (+3361.54%)
Mutual labels:  rspec, bdd
cppspec
BDD testing for C++ à la RSpec
Stars: ✭ 13 (-50%)
Mutual labels:  rspec, bdd
bdd
Given/When/Then/And/But output to RSpec and Minitest
Stars: ✭ 33 (+26.92%)
Mutual labels:  rspec, bdd
Everydayrails Rspec 2017
Sample source for the 2017 edition of Everyday Rails Testing with RSpec.
Stars: ✭ 280 (+976.92%)
Mutual labels:  rspec, bdd
Spectrum
A BDD-style test runner for Java 8. Inspired by Jasmine, RSpec, and Cucumber.
Stars: ✭ 142 (+446.15%)
Mutual labels:  rspec, bdd
Nspec
A battle hardened testing framework for C# that's heavily inspired by Mocha and RSpec.
Stars: ✭ 242 (+830.77%)
Mutual labels:  rspec, bdd
ginkgo4j
A Java BDD Testing Framework (based on RSpec and Ginkgo)
Stars: ✭ 25 (-3.85%)
Mutual labels:  rspec, bdd
pytest-pytorch
pytest plugin for a better developer experience when working with the PyTorch test suite
Stars: ✭ 36 (+38.46%)
Mutual labels:  pytest
pytest-snapshot
A plugin for snapshot testing with pytest.
Stars: ✭ 68 (+161.54%)
Mutual labels:  pytest
CtCI-with-Ruby-TDD
Cracking the Coding Interview with Ruby and TDD
Stars: ✭ 44 (+69.23%)
Mutual labels:  rspec
apple-mango
Python BDD Pattern
Stars: ✭ 18 (-30.77%)
Mutual labels:  bdd
pytest-notebook
A pytest plugin for regression testing and regenerating Jupyter Notebooks
Stars: ✭ 35 (+34.62%)
Mutual labels:  pytest
knapsack pro-ruby
Knapsack Pro gem splits tests across parallel CI nodes and makes sure that tests will run in optimal time on each node.
Stars: ✭ 101 (+288.46%)
Mutual labels:  rspec
gavel-spec
Behavior specification for Gavel, validator of HTTP transactions
Stars: ✭ 105 (+303.85%)
Mutual labels:  bdd
pytest-faulthandler
py.test plugin that activates the fault handler module during testing
Stars: ✭ 27 (+3.85%)
Mutual labels:  pytest
karate-runner
VSCode Extension for Karate
Stars: ✭ 23 (-11.54%)
Mutual labels:  bdd
myrepo
continuous integration rep
Stars: ✭ 41 (+57.69%)
Mutual labels:  pytest
reverse coverage
A tool to find the test examples which cover a specific line (or set of lines) of a Ruby project
Stars: ✭ 61 (+134.62%)
Mutual labels:  rspec
phpunit-expect
BDD-style assertions for PHPUnit
Stars: ✭ 15 (-42.31%)
Mutual labels:  bdd
pactum
REST API Testing Tool for all levels in a Test Pyramid
Stars: ✭ 190 (+630.77%)
Mutual labels:  bdd

pytest-it

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.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].