Git Product home page Git Product logo

pytest-deadfixtures's Introduction

pytest-deadfixtures

Donate See Build Status on Travis CI

A simple plugin to list unused or duplicated fixtures in a pytest suite.


Features

  • List unused fixtures in your tests
  • List duplicated fixtures

Installation

You can install "pytest-deadfixtures" via pip from PyPI:

$ pip install pytest-deadfixtures

Usage

Important

The --dead-fixtures option will not run your tests and it's also sensible for errors in the pytest collection step. If you are using as part of you CI process the recommended way is to run it after the default test run. For example:

script:
  - pytest
  - pytest --dead-fixtures

Listing unused fixtures

Just run 'pytest' with an extra option '--dead-fixtures':

$ pytest --dead-fixtures
============================= test session starts ==============================
(hidden for brevity)

Hey there, I believe the following fixture(s) are not being used:
Fixture name: some_fixture, location: test_write_docs_when_verbose.py:5

========================= no tests ran in 0.00 seconds =========================

Using some level of verbosity will also print the docstring of each fixture:

$ pytest --dead-fixtures -v
============================= test session starts ==============================
(hidden for brevity)

Hey there, I believe the following fixture(s) are not being used:
Fixture name: some_fixture, location: test_write_docs_when_verbose.py:5
    Blabla fixture docs

========================= no tests ran in 0.00 seconds =========================

Listing repeated fixtures

Now that you removed every unused fixture of your test suite, what if you want to go an extra mile?

An important note about this is that it uses the fixture return value to verify if two or more fixtures are equal.

This means fixtures without a truthy return value will be skipped.

You should use this as a hint only, verify that the functionality provided by both fixtures are really repeated before deleting one of them.

Just run 'pytest' with an extra option '--dup-fixtures', unlike the '--dead-fixtures' option, it'll normally run you tests:

$ pytest --dup-fixtures
======================================================================================================================== test session starts ========================================================================================================================
(hidden for brevity)

tests/test_deadfixtures.py ........

You may have some duplicate fixtures:
Fixture name: someclass_fixture, location: test_repeated_fixtures.py:12
Fixture name: someclass_samefixture, location: test_repeated_fixtures.py:17

Projects using it

Contributing

Contributions are very welcome. Tests can be run with tox, please ensure the coverage at least stays the same before you submit a pull request.

License

Distributed under the terms of the MIT license, 'pytest-deadfixtures' is free and open source software

Issues

If you encounter any problems, please file an issue along with a detailed description.

pytest-deadfixtures's People

Contributors

jllorencetti avatar jairhenrique avatar asottile avatar dirtycoder avatar sobolevn avatar tawonga avatar

Watchers

Eduardo "Stalinho" Oliveira de Carvalho avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.