test: allow running pytest without specifying the tests directory
This allows `pytest` to be executed from the top-level source or build directory (or any other directory below). Change-Id: Ib7af2ea2aaf01319d6839d2dc67228fbb5a7bc34 Reviewed-on: https://code.wireshark.org/review/31370 Petri-Dish: Peter Wu <peter@lekensteyn.nl> Tested-by: Petri Dish Buildbot Reviewed-by: Anders Broman <a.broman58@gmail.com>
This commit is contained in:
parent
f100f7f122
commit
2e411dba93
|
@ -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
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -58,7 +58,7 @@ before_test:
|
|||
- msbuild /m test-programs.vcxproj
|
||||
|
||||
test_script:
|
||||
- pytest -nauto ..\test
|
||||
- pytest -nauto
|
||||
|
||||
on_finish:
|
||||
- ps: |
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
[pytest]
|
||||
testpaths = test
|
||||
python_files = suite_*.py group_*.py
|
||||
addopts = -ra
|
|
@ -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)
|
||||
|
|
|
@ -1,3 +0,0 @@
|
|||
[pytest]
|
||||
python_files=suite_*.py group_*.py
|
||||
addopts = -ra
|
Loading…
Reference in New Issue