useful for bug reports and quick tests
test suite with conftest.py session-wide fixture that runs automatically at the end of the test suite
cd /tmp
mkdir tests
echo -e "import pytest\nfrom warnings import warn\[email protected](scope='session', autouse=True)\ndef run_check(request): yield; warn('\\\\n\\\\n*** This is global warning ***\\\\n')" > tests/conftest.py
echo -e "def test_a(): assert True\ndef test_b(): assert True\ndef test_c(): assert True" > tests/test_1.py
echo -e "def test_a(): assert True\ndef test_b(): assert True\ndef test_c(): assert True" > tests/test_2.py
pytest tests
cleaner teardown report in conftest.py:
echo -e "import pytest\[email protected](hookwrapper=True)\ndef pytest_terminal_summary(terminalreporter): yield; print('\n\n*** This is global warning ***\n')" > tests/conftest.py
Here a test (test_3.py::test_c
) fails only if a certain sequence of other tests is run before it.
mkdir tests
echo -e "import os, os.path;\nif os.path.exists('./tmp1'): os.remove('./tmp1')\nif os.path.exists('./tmp2'): os.remove('./tmp2')" > tests/conftest.py
echo -e "def test_a(): assert True\ndef test_b(): assert True\ndef test_c():\n with open('./tmp1', 'w') as f: f.write('')\n assert True" > tests/test_1.py
echo -e "def test_a(): assert True\ndef test_b(): assert True\ndef test_c():\n with open('./tmp2', 'w') as f: f.write('')\n assert True" > tests/test_2.py
echo -e "from os.path import exists\ndef test_a(): assert True\ndef test_b(): assert True\ndef test_c(): assert not (exists('./tmp1') and exists('./tmp2'))" > tests/test_3.py
pytest tests