Git Product home page Git Product logo

pytest-involve's Introduction

pytest-involve

PyPI version

Python versions

See Build Status on Travis CI

pytest-involve is a pytest plugin for running only tests which cover a given file or set of files. It's called pytest-involve because it lets you run only tests involving modules or members from those modules.

Usually with pytest the test set to run is specified and coverage collected based on that set. When pytest-involve is used, instead you specify the file(s) you want to cover, and test files are selected based on whether they import from those file(s) or not.

Usages

pytest-involve adds one command line argument to pytest, namely --involving. This can be provided a file path, a module import path (such as you would use in a Python interpreter), or either of the above suffixed with :: and the name of something defined in there:

pytest --involving ./path/to/file.py

pytest --involving importable.module.path

pytest --involving ./path/to/file.py::member

pytest --involving importable.module.path::member

This will have the effect of only collecting and running tests which are defined in modules whose imports overlap with the file(s) and member(s) specified with the --involving flag.

The plugin aims for recall over precision: It might run a few tests that aren't strictly necessary, but it shouldn't ignore any tests that are.

The ::member syntax will only work for things with a __file__ attribute (so, mostly classes and functions).

pytest-involve should play nicely with most other pytest plugins and command line tooling. One useful example is as follows:

git status -s | cut -c4- | grep .py | sed "s/^/--involving /" | xargs pytest

This will take all *.py files mentioned in the output of git status and provide them to pytest prefixed with --involving, which allows for quickly running unit tests relevant to the current state of the repository.


This pytest plugin was generated with Cookiecutter along with @hackebrot's cookiecutter-pytest-plugin template.

Features

  • Run unit tests covering specific file(s) via the command line flag --involving

Requirements

  • pytest
  • That's it.

Installation

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

$ pip install pytest-involve

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-involve" is free and open source software.

Issues

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

pytest-involve's People

Contributors

marginalhours avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

pytest-involve's Issues

Objects with an unhashable `__name__` property cause an exception

Some objects (unittest.mock._call for instance) have a __name__ property which isn't a string. This causes a predictable:

TypeError: unhashable type: '_Call'

In:

/pytest_involve.py:335: in get_members_by_file

The solution here is probably to check if __name__ is a string. It won't be very common; probably will just be anything using the descriptor api so that getattr returns a value when it shouldn't.

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.