Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

pytest-requires

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pytest-requires

A pytest plugin to elegantly skip tests with optional requirements

  • 0.1.0
  • PyPI
  • Socket score

Maintainers
1

pytest-requires

PyPI version

Python versions

Build status

A pytest plugin to elegantly skip tests with optional requirements


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

Features

  • decorate tests that require optional modules (with an optional minimum version) and gracefully skip them when the requirements aren't importable

Requirements

  • pytest

Installation

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

pip install pytest-requires

Usage

How to use pytest-requires

With pytest-requires, tests can be marked as requiring an external module as follows:

@pytest.mark.requires("dateutil")
def test_date_parsing():
    assert date_parsing() == RESULT

In this example if the python-dateutil module isn't installed the test is skipped. The import testing is all performed by pytest's builtin importorskip function.

Notes:

  • the minversion keyword can be given to specifiy a minimum acceptable version for the required module
  • multiple modules can be given as positional arguments, with the decorated tested being skipped if any of the given modules cannot be imported
  • in the case of multiple modules, only a single minversion can be given, and will be used for all modules; if an independent minversion is required for each module, use multiple @pytest.mark.requires decorators.

Why not just use pytest.importorskip?

pytest.importorskip is designed to import a module and add the module to the namespace (of the module, or the test function). If the optional module isn't used in the test itself, but is really a requirement of the function being tested, the call to importorskip less elegant (in the author's opinion) than a decorator call.

Contributing

Contributions are very welcome, please open a Pull Request.

License

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

Issues

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

FAQs


Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc