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 | |
| @pytest.fixture | |
| def function_fixture(): | |
| print('Fixture for each test') | |
| return 1 | |
| @pytest.fixture(scope='module') |
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 | |
| @pytest.fixture | |
| def simple_yield_fixture(): | |
| print('setUp part') | |
| yield 3 | |
| print('tearDown part') |
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
| def test_function_fixture(function_fixture): | |
| assert function_fixture == 1 | |
| def test_yield_fixture(simple_yield_fixture): | |
| assert simple_yield_fixture == 3 |
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 | |
| @pytest.mark.xfail | |
| def test_some_magic_test(): | |
| ... | |
| @pytest.mark.skip | |
| def test_old_functional(): |
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
| [pytest] | |
| markers = | |
| slow: marks tests as slow | |
| serial |
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 | |
| @pytest.mark.parametrize( | |
| 'text_input, result', [('5+5', 10), ('1+4', 5)] | |
| ) | |
| def test_sum(text_input, result): | |
| assert eval(text_input) == result |
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
| pytest -m "xfail and not slow" --strict-markers |
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
| pip install pytest-django |
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
| [pytest] | |
| DJANGO_SETTINGS_MODULE = yourproject.settings |
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
| [pytest] | |
| DJANGO_SETTINGS_MODULE = yourproject.settings | |
| python_files = tests.py test_*.py *_tests.py |
OlderNewer