Skip to main content

A LibCST codemod to remove pytest fixtures applied via the usefixtures decorator, as well as its parametrizations.

Project description

pytest fixture remove codemod

Code style: black codecov PyPI - Version PyPI - Python Version

A LibCST codemod to remove pytest fixtures applied via the usefixtures decorator, as well as its parametrizations.

[!NOTE] Only fixture usage will be removed, not its definition.

Usage

This package requires Python >= 3.8.

Install from PyPI.

pip install pytest-fixture-remover

Run against your tests, specifying a fixture to remove.

python -m libcst.tool codemod -x pytest_fixture_remover.RemovePytestFixtureCommand my_project_tests/ --name clean_db

Add --no-format option to stop LibCST from running Black against modified code.

Before/after examples can be found in the tests.test_command module.

Note on formatting

This codemod assumes that the target code is formatted with Black using the magic trailing comma. It may change the existing formatting in several ways:

  1. When removing a fixture name from the usefixtures call.
  2. When removing a value that parametrizes the fixture via parametrize.

In both cases the behavior is the same and obeys the following rules:

  1. If there's only one item left after modifying, remove the trailing comma.
  2. If there are multiple items left after modifying and the removed item was the last, preserve the last item's comma (or its absence).

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pytest_fixture_remover-1.0.1.post1.tar.gz (4.1 kB view hashes)

Uploaded Source

Built Distribution

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page