+``` + +To run the code in this post yourself, make sure you have +[`torch`](https://pypi.org/project/torch/), +[`ipytest>0.9`](https://pypi.org/project/ipytest/), and the plugin to be +introduced +[`pytest-pytorch`](https://github.com/Quansight/pytest-pytorch) +installed. + + pip install torch 'ipytest>0.9' pytest-pytorch + +Before we start testing, we need to configure +[`ipytest`](https://github.com/chmp/ipytest). We use the +[`ipytest.autoconfig()`](https://github.com/chmp/ipytest#ipytestautoconfig) +as base and add some [`pytest` CLI +flags](https://docs.pytest.org/en/stable/reference.html#command-line-flags) +in order to get a concise output. + +``` python +import ipytest + +ipytest.autoconfig(defopts=False) + +default_flags = ("--quiet", "--disable-warnings") + +def _configure_ipytest(*additional_flags, collect_only=False): + addopts = list(default_flags) + if collect_only: + addopts.append("--collect-only") + addopts.extend(additional_flags) + + ipytest.config(addopts=addopts) + +def enable_pytest_pytorch(collect_only=False): + _configure_ipytest(collect_only=collect_only) + +def disable_pytest_pytorch(collect_only=False): + _configure_ipytest("--disable-pytest-pytorch", collect_only=collect_only) + +disable_pytest_pytorch() +``` + +```{=ipynb} +
+