|
| 1 | +import unittest |
| 2 | + |
| 3 | +# By default, pytest read recursively all : |
| 4 | +# python_files = *_test.py |
| 5 | +# python_classes = *_Tests |
| 6 | +# python_functions = test test_* |
| 7 | + |
| 8 | +# But if a pytest.ini is overwritten, it is possible to change some parameters : |
| 9 | +# [pytest] |
| 10 | +# python_files=tst_*.py # Change the file names to read tst_* |
| 11 | +# python_classes=*_tests # *_tests or *_Tests are read |
| 12 | +# python_functions=test test_* |
| 13 | +class repeating_checks(): |
| 14 | + def test_01(self): assert (1 + 1 == 2) # tst_* file / *_Tests class / test_* method : read |
| 15 | + def Test_02(self): assert (1 + 1 == 2) # tst_* file / *_Tests class / test_* method : read |
| 16 | + def tests_03(self): assert (1 + 1 == 2) # tst_* file / *_Tests class / test_* method : read |
| 17 | + def Tests_04(self): assert (1 + 1 == 2) # tst_* file / *_Tests class / test_* method : read |
| 18 | + def check_05(self): assert [1, 2] == [1, 2] # tst_* file / *_Tests class / check_* method : not read |
| 19 | + def check_06_test(self): assert (1 + 1 == 2) # tst_* file / *_Tests class / test_* method : read |
| 20 | + def check_07_Test(self): assert (1 + 1 == 2) # tst_* file / *_Tests class / test_* method : read |
| 21 | + def check_08_tests(self): assert (1 + 1 == 2) # tst_* file / *_Tests class / test_* method : read |
| 22 | + def check_09_Tests(self): assert (1 + 1 == 2) # tst_* file / *_Tests class / test_* method : read |
| 23 | + |
| 24 | +class check_01_Tests(repeating_checks): pass |
| 25 | +# 01 : tst_* file / *_Tests class / test_* method : read |
| 26 | +# 02 : tst_* file / *_Tests class / Test_* method : read |
| 27 | +# 03 : tst_* file / *_Tests class / tests_* method : read |
| 28 | +class check_02_tests(repeating_checks): pass |
| 29 | +# 01 : tst_* file / *_tests class / test_* method : read |
| 30 | +# 02 : tst_* file / *_tests class / Test_* method : read |
| 31 | +# 03 : tst_* file / *_tests class / tests_* method : read |
| 32 | +class check_03_Test(repeating_checks): pass # not read |
| 33 | +class check_04_test(repeating_checks): pass # not read |
| 34 | +class check_05_TST(repeating_checks): pass # not read |
| 35 | +class Tests_check_06(repeating_checks): pass # not read |
| 36 | +class tests_check_07(repeating_checks): pass # not read |
| 37 | +class Test_check_08(repeating_checks): pass # not read |
| 38 | +class test_check_09(repeating_checks): pass # not read |
| 39 | +# Conclusion : the method must starts with the prefix 'test_*' 'Test_*' or 'tests_*' |
| 40 | +# and the class name must have the suffix '_Tests' or '_tests' to be read |
| 41 | + |
| 42 | +# except if the class inherits of unittest.TestCase, where the class name is not relevant |
| 43 | +class check_10_Tests(unittest.TestCase,repeating_checks): pass |
| 44 | +class check_11_tests(unittest.TestCase,repeating_checks): pass |
| 45 | +class check_12_Test(unittest.TestCase,repeating_checks): pass |
| 46 | +class check_13_test(unittest.TestCase,repeating_checks): pass |
| 47 | +class check_14_TST(unittest.TestCase,repeating_checks): pass |
| 48 | +class Tests_check_15(unittest.TestCase,repeating_checks): pass |
| 49 | +class tests_check_16(unittest.TestCase,repeating_checks): pass |
| 50 | +class Test_check_17(unittest.TestCase,repeating_checks): pass |
| 51 | +class test_check_18(unittest.TestCase,repeating_checks): pass |
| 52 | +# Conclusion : All methods starting with the prefix 'test_*' or 'tests_*' can be read |
| 53 | + |
| 54 | +# By default, FILES matching 'test_*.py' and '*_test.py' will be considered test modules |
| 55 | +# By default, pytest will consider any FUNCTION prefixed with 'test' (lowercase) as a test |
| 56 | + |
| 57 | +# A directory can be set by pythonpath = src1 src2 or by using the -k <dir> option with pytest |
| 58 | +# There is no recurse in folder '*.egg', '.*', '_darcs', 'build', 'CVS', 'dist', 'node_modules', 'venv', '{arch}' |
| 59 | +# and more can be added by norecursedirs = .svn _build tmp* |
| 60 | + |
| 61 | +# PRO : The recommendation is to only use these configuration options for legacy projects that follow a different |
| 62 | +# convention, and stick with the defaults for new projects. Using the defaults is less work and avoids confusing |
| 63 | +# for other collaborators. |
| 64 | + |
| 65 | +# Src : https://buildmedia.readthedocs.org/media/pdf/pytest/latest/pytest.pdf |
0 commit comments