Last active
March 19, 2018 17:26
-
-
Save billyshambrook/264624b039fb3caa9278 to your computer and use it in GitHub Desktop.
Categorise integration tests using PyTest.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pytest | |
def pytest_addoption(parser): | |
parser.addoption("--integration", action="store_true", help="run integration tests") | |
def pytest_runtest_setup(item): | |
if 'integration' in item.keywords: | |
item.config.getoption("--integration", skip=True) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pytest | |
def test_unit_test(): | |
assert True | |
@pytest.mark.integration | |
def test_integration_test(): | |
assert True |
That's great, thanks for the share @tasosval
This is what I ended up with, the logic could be very different depending on the use case:
def pytest_addoption(parser):
parser.addoption("--integration", action="store_true", help="run integration tests")
def pytest_runtest_setup(item):
"""
Only run tests marked with 'integration' when --integration is passed
"""
run_integration = item.config.getoption("--integration")
if run_integration and 'integration' not in item.keywords:
pytest.skip("skipping test not marked as integration")
elif 'integration' in item.keywords and not run_integration:
pytest.skip("pass --integration option to pytest to run this test")
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Using pytest 3.0.3 the conftest.py provided failed for me throwing a ValueError.
This is what worked for me.