Skip to content

pytest plugin for a better developer experience when working with the PyTorch test suite

License

Notifications You must be signed in to change notification settings

Quansight/pytest-pytorch

pytest-pytorch

license repo status isort black tests status

What is it?

pytest-pytorch is a lightweight pytest-plugin that enhances the developer experience when working with the PyTorch test suite if you come from a pytest background.

Why do I need it?

Some testcases in the PyTorch test suite are only used as templates and will be instantiated at runtime. Unfortunately, PyTorch's naming scheme for parametrizations differs from pytest's. As a consequence, these tests cannot be selected by their names as written and one has to remember PyTorch's naming scheme. This can be especially disrupting to your workflow if your IDE (PyCharm, VSCode) relies on pytest's default selection syntax.

If this has ever been a source of frustration for you, worry no longer. pytest-pytorch was made for you.

How do I install it?

You can install pytest-pytorch with pip

$ pip install pytest-pytorch

or with conda:

$ conda install -c conda-forge pytest-pytorch

How do I use it?

With pytest-pytorch installed you can select test cases and tests by their names as written:

Use case Command
Run a test case against all devices pytest test_foo.py::TestBar
Run a test against all devices pytest test_foo.py::TestBar::test_baz

Similar to a parametrization by @pytest.mark.parametrize you can use the -k flag to select a specific set of parameters:

Use case Command
Run a test case against one device pytest test_foo.py::TestBar -k "$DEVICE"
Run a test against one device pytest test_foo.py::TestBar::test_baz -k "$DEVICE"

Can I have a little more background?

Sure, we have written a blog post about pytest-pytorch that goes into details.

How do I contribute?

First and foremost: Thank you for your interest in development of pytest-pytorch's! We appreciate all contributions be it code or something else. Check out our contribution guide lines for details.