diff options
-rw-r--r-- | .travis.yml | 2 | ||||
-rw-r--r-- | CMakeLists.txt | 9 | ||||
-rw-r--r-- | appveyor.yml | 2 | ||||
-rw-r--r-- | pytest.ini | 4 | ||||
-rw-r--r-- | test/conftest.py | 9 | ||||
-rw-r--r-- | test/pytest.ini | 3 |
6 files changed, 22 insertions, 7 deletions
diff --git a/.travis.yml b/.travis.yml index ed47fbd7d0..959c9dc4e8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -72,6 +72,6 @@ before_script: script: - ninja - ninja test-programs - - pytest -nauto -v ../test + - pytest -nauto -v after_script: - if [ -f run/tshark ]; then run/tshark --version; fi diff --git a/CMakeLists.txt b/CMakeLists.txt index e175bc6177..275b0b46f7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3170,6 +3170,15 @@ foreach(_group_name ${_test_group_list}) set_tests_properties(${_group_name} PROPERTIES TIMEOUT 600) endforeach() +# Make it possible to run pytest without passing the full path as argument. +if(NOT CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR) + file(READ "${CMAKE_CURRENT_SOURCE_DIR}/pytest.ini" pytest_ini) + string(REGEX REPLACE "\naddopts = ([^\n]+)" + "\naddopts = ${CMAKE_CURRENT_SOURCE_DIR}/test \\1" + pytest_ini "${pytest_ini}") + file(WRITE "${CMAKE_BINARY_DIR}/pytest.ini" "${pytest_ini}") +endif() + if (GIT_EXECUTABLE) # Update AUTHORS file with entries from git shortlog add_custom_target( diff --git a/appveyor.yml b/appveyor.yml index 2db2f0679c..6e200f290f 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -58,7 +58,7 @@ before_test: - msbuild /m test-programs.vcxproj test_script: - - pytest -nauto ..\test + - pytest -nauto on_finish: - ps: | diff --git a/pytest.ini b/pytest.ini new file mode 100644 index 0000000000..b12b8b0f8e --- /dev/null +++ b/pytest.ini @@ -0,0 +1,4 @@ +[pytest] +testpaths = test +python_files = suite_*.py group_*.py +addopts = -ra diff --git a/test/conftest.py b/test/conftest.py index c2646bf7a8..2146cb46a3 100644 --- a/test/conftest.py +++ b/test/conftest.py @@ -6,8 +6,9 @@ # # SPDX-License-Identifier: GPL-2.0-or-later # -'''py.test configuration''' +'''pytest configuration''' +import re import fixtures def pytest_addoption(parser): @@ -27,7 +28,11 @@ def pytest_collection_modifyitems(items): global _all_test_groups suites = [] for item in items: - name = item.nodeid.split("::")[0].replace(".py", "").replace("/", ".") + name = item.nodeid.split("::")[0].replace(".py", "") + # When executed from the rootdir (e.g. "pytest test"), be sure to strip + # all preceding components ("test/suite_io" -> "suite_io"). + name = re.sub(r'^.*/suite_', 'suite_', name) + name = name.replace("/", ".") if name not in suites: suites.append(name) _all_test_groups = sorted(suites) diff --git a/test/pytest.ini b/test/pytest.ini deleted file mode 100644 index 4ec2f9ee11..0000000000 --- a/test/pytest.ini +++ /dev/null @@ -1,3 +0,0 @@ -[pytest] -python_files=suite_*.py group_*.py -addopts = -ra |