You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by jd...@apache.org on 2021/04/26 08:44:06 UTC
[qpid-dispatch] branch main updated: DISPATCH-1933 Tests should
produce JUnit-compatible XML report about individual tests (not aggregated
CTest test targets) (#1102)
This is an automated email from the ASF dual-hosted git repository.
jdanek pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/qpid-dispatch.git
The following commit(s) were added to refs/heads/main by this push:
new 1e08367 DISPATCH-1933 Tests should produce JUnit-compatible XML report about individual tests (not aggregated CTest test targets) (#1102)
1e08367 is described below
commit 1e08367b28833089dc0cb2afecfa129806a7358c
Author: Jiri Daněk <jd...@redhat.com>
AuthorDate: Mon Apr 26 10:44:01 2021 +0200
DISPATCH-1933 Tests should produce JUnit-compatible XML report about individual tests (not aggregated CTest test targets) (#1102)
---
.github/workflows/build.yaml | 3 ++-
CMakeLists.txt | 3 ++-
README | 7 +++++--
tests/CMakeLists.txt | 22 ++++++++++++++++------
tests/{management => management_test}/__init__.py | 0
tests/{management => management_test}/entity.py | 0
tests/{management => management_test}/qdrouter.py | 0
tests/{management => management_test}/schema.py | 0
tests/system_test.py | 8 ++++----
tests/system_tests_deprecated.py | 4 ++--
tests/tox.ini.in | 5 +++++
11 files changed, 36 insertions(+), 16 deletions(-)
diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml
index 72ac9b8..7740f11 100644
--- a/.github/workflows/build.yaml
+++ b/.github/workflows/build.yaml
@@ -133,6 +133,7 @@ jobs:
cmake "${{github.workspace}}/qpid-dispatch" \
"-DCMAKE_INSTALL_PREFIX=${InstallPrefix}" \
"-DCMAKE_BUILD_TYPE=${BuildType}" \
+ "-DPYTHON_TEST_COMMAND='-m;pytest;-vs;--junit-prefix=pytest.\${py_test_module};--junit-xml=junitxmls/\${py_test_module}.xml;--pyargs;\${py_test_module}'" \
"-GNinja" \
${DispatchCMakeExtraArgs}
@@ -199,7 +200,7 @@ jobs:
architecture: x64
- name: Install Python runtime/test dependencies
- run: python -m pip install tox quart selectors grpcio protobuf
+ run: python -m pip install tox quart selectors grpcio protobuf pytest
- name: Install Linux runtime/test dependencies
if: ${{ runner.os == 'Linux' }}
diff --git a/CMakeLists.txt b/CMakeLists.txt
index a05369f..7ddf252 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -155,7 +155,8 @@ endif (NOT DEFINED DISPATCH_TEST_TIMEOUT)
SET(DART_TESTING_TIMEOUT ${DISPATCH_TEST_TIMEOUT} CACHE STRING "Default CTest timeout in seconds")
include (CTest)
-set(PYTHON_TEST_COMMAND "-m" "unittest")
+set(PYTHON_TEST_COMMAND "-m" "unittest" "-v" "\${py_test_module}"
+ CACHE STRING "Command used to run tests implemented in Python unittest; \${py_test_module} will be replaced with test module name.")
set (SO_VERSION_MAJOR 2)
set (SO_VERSION_MINOR 0)
diff --git a/README b/README
index 45a4480..b0c3f9e 100644
--- a/README
+++ b/README
@@ -23,8 +23,6 @@ packages installed:
- asciidoc (for building docs)
- asciidoctor (for building docs)
-The unit tests are implemented using Python's unittest library.
-
Dispatch will not build on Windows.
To build formatted documentation (man pages, HTML, PDF) see the requirements in doc/README
@@ -81,6 +79,11 @@ you must also install the following dependency:
And run the following command to generate grpc code:
- python -m grpc_tools.protoc -I. --python_out=. --grpc_python_out=. ./friendship.proto
+The system tests are implemented using Python's unittest library. This library is
+used to run the tests by default. The tests can be also run using `xmlrunner` or `pytest`.
+Pytest can generate a JUnit-compatible XML report containing an entry for each Python test method.
+After running the tests, all XML reports will be found under tests/junitxmls in your build directory:
+ - cmake .. -DPYTHON_TEST_COMMAND='-m;pytest;-vs;--junit-xml=junitxmls/${py_test_module}.xml;--pyargs;${py_test_module}'
Test Suite Code Coverage (GNU tools only)
=========================================
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index 5b1ffec..a64819f 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -84,10 +84,17 @@ add_test(unit_tests_size_1 ${TEST_WRAP} unit_tests_size 1)
add_test(unit_tests ${TEST_WRAP} unit_tests ${CMAKE_CURRENT_SOURCE_DIR}/threads4.conf)
# Unit test python modules
-add_test(router_engine_test ${TEST_WRAP} ${PYTHON_TEST_COMMAND} -v router_engine_test)
-add_test(management_test ${TEST_WRAP} ${PYTHON_TEST_COMMAND} -v management)
-add_test(router_policy_test ${TEST_WRAP} ${PYTHON_TEST_COMMAND} -v router_policy_test)
-add_test(test_command ${TEST_WRAP} ${PYTHON_TEST_COMMAND} -v test_command)
+foreach(py_test_module
+ router_engine_test
+ management_test
+ router_policy_test
+ test_command
+ )
+
+ string(CONFIGURE "${PYTHON_TEST_COMMAND}" CONFIGURED_PYTHON_TEST_COMMAND)
+
+ add_test(${py_test_module} ${TEST_WRAP} ${CONFIGURED_PYTHON_TEST_COMMAND})
+endforeach()
if(USE_LIBWEBSOCKETS)
set(SYSTEM_TESTS_HTTP system_tests_http)
@@ -166,10 +173,14 @@ foreach(py_test_module
system_tests_tcp_adaptor
)
- add_test(${py_test_module} ${TEST_WRAP} ${PYTHON_TEST_COMMAND} -v ${py_test_module})
+ string(CONFIGURE "${PYTHON_TEST_COMMAND}" CONFIGURED_PYTHON_TEST_COMMAND)
+
+ add_test(${py_test_module} ${TEST_WRAP} ${CONFIGURED_PYTHON_TEST_COMMAND})
list(APPEND SYSTEM_TEST_FILES ${CMAKE_CURRENT_SOURCE_DIR}/${py_test_module}.py)
endforeach()
+# Location of tox.ini determines the testroot directory for Pytest
+configure_file(${CMAKE_CURRENT_SOURCE_DIR}/tox.ini.in ${CMAKE_CURRENT_BINARY_DIR}/tox.ini)
# Use tox to run the flake8 python linter tool on all the python
# sources. Highly recommended if you're hacking the python code.
# Unfortunately this can only be done for versions of tox >= 1.9.0
@@ -190,7 +201,6 @@ if (TOX_EXE)
if (TOX_VERSION STRLESS TOX_MIN_VERSION)
message( STATUS "tox version ${TOX_VERSION} < required version ${TOX_MIN_VERSION} - skipping python-checker")
else (TOX_VERSION STRLESS TOX_MIN_VERSION)
- configure_file(${CMAKE_CURRENT_SOURCE_DIR}/tox.ini.in ${CMAKE_CURRENT_BINARY_DIR}/tox.ini)
add_test (NAME python-checker
COMMAND ${TOX_EXE}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
diff --git a/tests/management/__init__.py b/tests/management_test/__init__.py
similarity index 100%
rename from tests/management/__init__.py
rename to tests/management_test/__init__.py
diff --git a/tests/management/entity.py b/tests/management_test/entity.py
similarity index 100%
rename from tests/management/entity.py
rename to tests/management_test/entity.py
diff --git a/tests/management/qdrouter.py b/tests/management_test/qdrouter.py
similarity index 100%
rename from tests/management/qdrouter.py
rename to tests/management_test/qdrouter.py
diff --git a/tests/management/schema.py b/tests/management_test/schema.py
similarity index 100%
rename from tests/management/schema.py
rename to tests/management_test/schema.py
diff --git a/tests/system_test.py b/tests/system_test.py
index 10672bc..adda621 100755
--- a/tests/system_test.py
+++ b/tests/system_test.py
@@ -262,8 +262,8 @@ class Process(subprocess.Popen):
Takes same arguments as subprocess.Popen. Some additional/special args:
@param expect: Raise error if process staus not as expected at end of test:
L{RUNNING} - expect still running.
- L{EXIT_OK} - expect proces to have terminated with 0 exit status.
- L{EXIT_FAIL} - expect proces to have terminated with exit status 1.
+ L{EXIT_OK} - expect process to have terminated with 0 exit status.
+ L{EXIT_FAIL} - expect process to have terminated with exit status 1.
integer - expected return code
@keyword stdout: Defaults to the file name+".out"
@keyword stderr: Defaults to be the same as stdout
@@ -360,10 +360,10 @@ class HttpServer(Process):
def __init__(self, args, name=None, expect=Process.RUNNING):
super(HttpServer, self).__init__(args, name=name, expect=expect)
-# A HTTP2 Server that will respond to requests made via the router
-
class Http2Server(HttpServer):
+ """A HTTP2 Server that will respond to requests made via the router."""
+
def __init__(self, name=None, listen_port=None, wait=True,
py_string='python3', perform_teardown=True, cl_args=None,
server_file=None,
diff --git a/tests/system_tests_deprecated.py b/tests/system_tests_deprecated.py
index b9142d6..d5b2091 100644
--- a/tests/system_tests_deprecated.py
+++ b/tests/system_tests_deprecated.py
@@ -55,7 +55,7 @@ class RouterTestDeprecatedLinkRoute(TestCase):
pass
def test_deprecated_link_route(self):
- with open('../setUpClass/test-router-2.out', 'r') as router_log:
+ with open(self.router.outfile + '.out', 'r') as router_log:
log_lines = router_log.read().split("\n")
search_lines = [s for s in log_lines if "org.apache.qpid.dispatch.router.config.linkRoute: Both 'dir' and 'direction' cannot be specified for entity 'linkRoute'" in s]
self.assertTrue(len(search_lines) > 0)
@@ -90,7 +90,7 @@ class RouterTestDeprecatedLAutoLink(TestCase):
pass
def test_deprecated_auto_link(self):
- with open('../setUpClass/test-autolink-1.out', 'r') as router_log:
+ with open(self.router.outfile + '.out', 'r') as router_log:
log_lines = router_log.read().split("\n")
search_lines = [s for s in log_lines if
"org.apache.qpid.dispatch.router.config.autoLink: Both 'dir' and 'direction' cannot be specified for entity 'autoLink'" in s]
diff --git a/tests/tox.ini.in b/tests/tox.ini.in
index 9ce4602..acc45a7 100644
--- a/tests/tox.ini.in
+++ b/tests/tox.ini.in
@@ -117,3 +117,8 @@ exclude =
# TODO(DISPATCH-1974) generated by gRPC tooling
friendship_pb2.py,
friendship_pb2_grpc.py,
+
+[pytest]
+# https://github.com/pytest-dev/pytest/blob/main/src/_pytest/junitxml.py
+# do not filter test file names
+python_files = *.py
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org