├── .github └── workflows │ ├── main.yml │ └── publish-to-pypi.yml ├── .gitignore ├── LICENSE ├── README.md ├── examples └── test_slow.py ├── pyproject.toml ├── pytest_skip_slow.py ├── tests ├── conftest.py └── test_plugin.py └── tox.ini /.github/workflows/main.yml: -------------------------------------------------------------------------------- 1 | name: main 2 | 3 | on: [push, pull_request] 4 | 5 | jobs: 6 | build: 7 | 8 | runs-on: ubuntu-latest 9 | strategy: 10 | matrix: 11 | python: ["3.7", "3.8", "3.9", "3.10", "3.11"] 12 | 13 | steps: 14 | - uses: actions/checkout@v3 15 | - name: Setup Python 16 | uses: actions/setup-python@v4 17 | with: 18 | python-version: ${{ matrix.python }} 19 | - name: Install Tox and any other packages 20 | run: pip install tox 21 | - name: Run Tox 22 | run: tox -e py -------------------------------------------------------------------------------- /.github/workflows/publish-to-pypi.yml: -------------------------------------------------------------------------------- 1 | name: Publish to PyPI and TestPyPI 2 | 3 | on: push 4 | 5 | jobs: 6 | build-n-publish: 7 | name: Build and publish to PyPI and TestPyPI 8 | if: startsWith(github.ref, 'refs/tags') 9 | runs-on: ubuntu-latest 10 | steps: 11 | - uses: actions/checkout@v3 12 | - name: Set up Python 3.11 13 | uses: actions/setup-python@v4 14 | with: 15 | python-version: "3.11" 16 | - name: Install pypa/build 17 | run: python -m pip install build --user 18 | - name: Build a binary wheel and a source tarball 19 | run: python -m build --sdist --wheel --outdir dist/ 20 | - name: Publish to Test PyPI 21 | uses: pypa/gh-action-pypi-publish@release/v1 22 | with: 23 | password: ${{ secrets.TEST_PYPI_API_TOKEN }} 24 | repository_url: https://test.pypi.org/legacy/ 25 | - name: Publish to PyPI 26 | uses: pypa/gh-action-pypi-publish@release/v1 27 | with: 28 | password: ${{ secrets.PYPI_API_TOKEN }} -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | build/ 12 | develop-eggs/ 13 | dist/ 14 | downloads/ 15 | eggs/ 16 | .eggs/ 17 | lib/ 18 | lib64/ 19 | parts/ 20 | sdist/ 21 | var/ 22 | wheels/ 23 | pip-wheel-metadata/ 24 | share/python-wheels/ 25 | *.egg-info/ 26 | .installed.cfg 27 | *.egg 28 | MANIFEST 29 | 30 | # PyInstaller 31 | # Usually these files are written by a python script from a template 32 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 33 | *.manifest 34 | *.spec 35 | 36 | # Installer logs 37 | pip-log.txt 38 | pip-delete-this-directory.txt 39 | 40 | # Unit test / coverage reports 41 | htmlcov/ 42 | .tox/ 43 | .nox/ 44 | .coverage 45 | .coverage.* 46 | .cache 47 | nosetests.xml 48 | coverage.xml 49 | *.cover 50 | *.py,cover 51 | .hypothesis/ 52 | .pytest_cache/ 53 | 54 | # Translations 55 | *.mo 56 | *.pot 57 | 58 | # Django stuff: 59 | *.log 60 | local_settings.py 61 | db.sqlite3 62 | db.sqlite3-journal 63 | 64 | # Flask stuff: 65 | instance/ 66 | .webassets-cache 67 | 68 | # Scrapy stuff: 69 | .scrapy 70 | 71 | # Sphinx documentation 72 | docs/_build/ 73 | 74 | # PyBuilder 75 | target/ 76 | 77 | # Jupyter Notebook 78 | .ipynb_checkpoints 79 | 80 | # IPython 81 | profile_default/ 82 | ipython_config.py 83 | 84 | # pyenv 85 | .python-version 86 | 87 | # pipenv 88 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. 89 | # However, in case of collaboration, if having platform-specific dependencies or dependencies 90 | # having no cross-platform support, pipenv may install dependencies that don't work, or not 91 | # install all needed dependencies. 92 | #Pipfile.lock 93 | 94 | # PEP 582; used by e.g. github.com/David-OConnor/pyflow 95 | __pypackages__/ 96 | 97 | # Celery stuff 98 | celerybeat-schedule 99 | celerybeat.pid 100 | 101 | # SageMath parsed files 102 | *.sage.py 103 | 104 | # Environments 105 | .env 106 | .venv 107 | env/ 108 | venv/ 109 | ENV/ 110 | env.bak/ 111 | venv.bak/ 112 | 113 | # Spyder project settings 114 | .spyderproject 115 | .spyproject 116 | 117 | # Rope project settings 118 | .ropeproject 119 | 120 | # mkdocs documentation 121 | /site 122 | 123 | # mypy 124 | .mypy_cache/ 125 | .dmypy.json 126 | dmypy.json 127 | 128 | # Pyre type checker 129 | .pyre/ 130 | 131 | # PyCharm 132 | .idea/ -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2021 Brian Okken 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # pytest-skip-slow 2 | 3 | A pytest plugin to skip `@pytest.mark.slow` tests by default. 4 | Include the slow tests with `--slow`. 5 | 6 | ## Installation 7 | 8 | ``` 9 | $ pip install pytest-skip-slow 10 | ``` 11 | 12 | ## Usage 13 | 14 | Example `test_slow.py`: 15 | 16 | ```python 17 | import pytest 18 | 19 | def test_normal(): 20 | pass 21 | 22 | @pytest.mark.slow 23 | def test_slow(): 24 | pass 25 | ``` 26 | 27 | Normal pytest sessions skip slow tests: 28 | 29 | ```shell 30 | (venv) $ pytest -v test_slow.py 31 | ========================= test session starts ========================== 32 | collected 2 items 33 | 34 | test_slow.py::test_normal PASSED [ 50%] 35 | test_slow.py::test_slow SKIPPED (need --slow option to run) [100%] 36 | 37 | ===================== 1 passed, 1 skipped in 0.00s ===================== 38 | ``` 39 | 40 | Include the slow tests with `--slow`: 41 | 42 | 43 | ```shell 44 | (venv) $ pytest -v --slow test_slow.py 45 | ========================= test session starts ========================== 46 | collected 2 items 47 | 48 | test_slow.py::test_normal PASSED [ 50%] 49 | test_slow.py::test_slow PASSED [100%] 50 | 51 | ========================== 2 passed in 0.00s =========================== 52 | ``` 53 | 54 | Run only the slow tests with `-m slow --slow`: 55 | ```shell 56 | (venv) $ pytest -v -m slow --slow test_slow.py 57 | ========================= test session starts ========================== 58 | collected 2 items / 1 deselected / 1 selected 59 | 60 | test_slow.py::test_slow PASSED [100%] 61 | 62 | =================== 1 passed, 1 deselected in 0.00s ==================== 63 | ``` 64 | -------------------------------------------------------------------------------- /examples/test_slow.py: -------------------------------------------------------------------------------- 1 | import pytest 2 | 3 | 4 | def test_normal(): 5 | pass 6 | 7 | 8 | @pytest.mark.slow 9 | def test_slow(): 10 | pass 11 | -------------------------------------------------------------------------------- /pyproject.toml: -------------------------------------------------------------------------------- 1 | [build-system] 2 | requires = ["flit_core >=3.2,<4"] 3 | build-backend = "flit_core.buildapi" 4 | 5 | [project] 6 | name = "pytest-skip-slow" 7 | authors = [{name = "Brian Okken", email = "brian+pypi@pythontest.com"}] 8 | readme = "README.md" 9 | classifiers = [ 10 | "License :: OSI Approved :: MIT License", 11 | "Framework :: Pytest" 12 | ] 13 | dynamic = ["version", "description"] 14 | dependencies = ["pytest>=6.2.0"] 15 | requires-python = ">=3.7" 16 | 17 | [project.urls] 18 | Home = "https://github.com/okken/pytest-skip-slow" 19 | 20 | [project.entry-points.pytest11] 21 | skip_slow = "pytest_skip_slow" 22 | 23 | [project.optional-dependencies] 24 | test = ["tox"] 25 | 26 | [tool.flit.module] 27 | name = "pytest_skip_slow" 28 | -------------------------------------------------------------------------------- /pytest_skip_slow.py: -------------------------------------------------------------------------------- 1 | """ 2 | A pytest plugin to skip `@pytest.mark.slow` tests by default. 3 | Include the slow tests with `--slow`. 4 | """ 5 | 6 | import pytest 7 | 8 | 9 | __version__ = "0.0.5" 10 | 11 | 12 | def pytest_configure(config): 13 | config.addinivalue_line("markers", "slow: mark test as slow to run") 14 | 15 | 16 | def pytest_addoption(parser): 17 | parser.addoption("--slow", action="store_true", 18 | help="include tests marked slow") 19 | 20 | 21 | def pytest_collection_modifyitems(config, items): 22 | if not config.getoption("--slow"): 23 | skip_slow = pytest.mark.skip(reason="need --slow option to run") 24 | for item in items: 25 | if item.get_closest_marker("slow"): 26 | item.add_marker(skip_slow) 27 | -------------------------------------------------------------------------------- /tests/conftest.py: -------------------------------------------------------------------------------- 1 | pytest_plugins = ["pytester"] 2 | -------------------------------------------------------------------------------- /tests/test_plugin.py: -------------------------------------------------------------------------------- 1 | import pytest 2 | 3 | 4 | @pytest.fixture() 5 | def examples(pytester): 6 | pytester.copy_example("examples/test_slow.py") 7 | 8 | 9 | def test_skip_slow(pytester, examples): 10 | result = pytester.runpytest("-v") 11 | result.stdout.fnmatch_lines( 12 | [ 13 | "*test_normal PASSED*", 14 | "*test_slow SKIPPED (need --slow option to run)*", 15 | ] 16 | ) 17 | result.assert_outcomes(passed=1, skipped=1) 18 | 19 | 20 | def test_run_slow(pytester, examples): 21 | result = pytester.runpytest("--slow") 22 | result.assert_outcomes(passed=2) 23 | 24 | 25 | def test_run_only_slow(pytester, examples): 26 | result = pytester.runpytest("-v", "-m", "slow", "--slow") 27 | result.stdout.fnmatch_lines(["*test_slow PASSED*"]) 28 | outcomes = result.parseoutcomes() 29 | assert outcomes["passed"] == 1 30 | assert outcomes["deselected"] == 1 31 | 32 | 33 | def test_help(pytester): 34 | result = pytester.runpytest("--help") 35 | result.stdout.fnmatch_lines(["*--slow * include tests marked slow*"]) 36 | -------------------------------------------------------------------------------- /tox.ini: -------------------------------------------------------------------------------- 1 | [pytest] 2 | testpaths = tests 3 | 4 | [tox] 5 | isolated_build = True 6 | envlist = 7 | py{37, 38, 39, 310, 311}-pytestlatest 8 | py311-pytest{62,main} 9 | 10 | [testenv] 11 | deps = 12 | pytest62: pytest==6.2.5 13 | pytestlatest: pytest 14 | pytestmain: git+https://github.com/pytest-dev/pytest.git 15 | 16 | commands = pytest {posargs:tests} 17 | description = Run pytest 18 | --------------------------------------------------------------------------------