Skip to content

Commit d82f9f9

Browse files
committed
build: add pytest targets
It enables running pytests in cmake jobs, regardless of underlying build tool choice (= makes it work with ninja.) Also: - drop pytest logic launching `make` and exiting in case of failure. Maybe there is a better way and keep this functionality somehow, bind it to a command-line option? make it fail softly? - GHA/linux: invoke pytest via the build, not directly. - autotools: add missing dummy runtests targets when cross-compiling. Closes curl#15034
1 parent ed76675 commit d82f9f9

File tree

7 files changed

+49
-17
lines changed

7 files changed

+49
-17
lines changed

.github/workflows/linux.yml

+8-5
Original file line numberDiff line numberDiff line change
@@ -652,14 +652,17 @@ jobs:
652652
fi
653653
make V=1 VERBOSE=1 test-ci
654654
655-
- if: contains(matrix.build.install_steps, 'pytest')
656-
# run for `tests/http` directory, so pytest does not pick up any other
657-
# packages we might have built here
658-
run: pytest -v tests/http
659-
name: 'run pytest'
655+
- name: 'run pytest'
656+
if: contains(matrix.build.install_steps, 'pytest')
660657
env:
661658
TFLAGS: "${{ matrix.build.tflags }}"
662659
CURL_CI: github
660+
run: |
661+
if [ -n '${{ matrix.build.generate }}' ]; then
662+
cmake --build . --verbose --target curl-pytest-ci
663+
else
664+
make V=1 pytest-ci
665+
fi
663666
664667
- run: ${{ matrix.build.make-prefix }} make V=1 examples
665668
if: ${{ matrix.build.configure }}

Makefile.am

+12
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,13 @@ check: test examples check-docs
118118

119119
if CROSSCOMPILING
120120
test-full: test
121+
test-nonflaky: test
121122
test-torture: test
123+
test-event: test
124+
test-am: test
125+
test-ci: test
126+
pytest: test
127+
pytest-ci: test
122128

123129
test:
124130
@echo "NOTICE: we can't run the tests when cross-compiling!"
@@ -146,6 +152,12 @@ test-am:
146152
test-ci:
147153
@(cd tests; $(MAKE) all ci-test)
148154

155+
pytest:
156+
@(cd tests; $(MAKE) all default-pytest)
157+
158+
pytest-ci:
159+
@(cd tests; $(MAKE) all ci-pytest)
160+
149161
endif
150162

151163
examples:

tests/CMakeLists.txt

+18-1
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,10 @@ function(add_runtests _targetname _test_flags)
4343
if(CURL_TEST_BUNDLES)
4444
set(_test_flags "${_test_flags} -bundle")
4545
endif()
46-
unset(_depends)
4746
# Skip walking through dependent targets before running tests in CI.
4847
# This avoids: GNU Make doing a slow re-evaluation of all targets and
4948
# skipping them, MSBuild doing a re-evaluation, and actually rebuilding them.
49+
unset(_depends)
5050
if(NOT _targetname STREQUAL "test-ci")
5151
set(_depends "testdeps")
5252
endif()
@@ -65,6 +65,20 @@ function(add_runtests _targetname _test_flags)
6565
)
6666
endfunction()
6767

68+
function(add_pytest _targetname _test_flags)
69+
unset(_depends)
70+
if(NOT _targetname STREQUAL "pytest-ci")
71+
set(_depends "test-http-clients")
72+
endif()
73+
string(REPLACE " " ";" _test_flags_list "${_test_flags}")
74+
add_custom_target(${_targetname}
75+
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
76+
COMMAND pytest ${_test_flags_list} "${CMAKE_CURRENT_SOURCE_DIR}/http"
77+
DEPENDS "${_depends}"
78+
VERBATIM USES_TERMINAL
79+
)
80+
endfunction()
81+
6882
# Create configurehelp.pm, used by tests needing to run the C preprocessor.
6983
if(MSVC OR CMAKE_COMPILER_IS_GNUCC OR CMAKE_C_COMPILER_ID MATCHES "Clang")
7084
set(CURL_CPP "\"${CMAKE_C_COMPILER}\" -E")
@@ -94,3 +108,6 @@ add_runtests(test-nonflaky "-a -p ~flaky ~timing-dependent")
94108
add_runtests(test-ci "-a -p ~flaky ~timing-dependent -r -rm -j2")
95109
add_runtests(test-torture "-a -t -j2")
96110
add_runtests(test-event "-a -e")
111+
112+
add_pytest(curl-pytest "")
113+
add_pytest(curl-pytest-ci "-v")

tests/Makefile.am

+8
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ TEST_COMMON =
122122

123123
if CROSSCOMPILING
124124
TEST = @echo "NOTICE: we can't run the tests when cross-compiling!"
125+
PYTEST = $(TEST)
125126
else # if not cross-compiling:
126127
if USE_TEST_BUNDLES
127128
TEST_COMMON += -bundle
@@ -140,6 +141,8 @@ TEST_NF = -a -p ~flaky ~timing-dependent
140141

141142
# special CI target derived from nonflaky with CI-specific flags
142143
TEST_CI = $(TEST_NF) -r -rm -j2
144+
145+
PYTEST = pytest
143146
endif
144147

145148
CD2NROFF = $(top_srcdir)/scripts/cd2nroff $< >$@
@@ -177,6 +180,11 @@ torture-test: perlcheck all
177180
event-test: perlcheck all
178181
$(TEST) $(TEST_E) $(TFLAGS)
179182

183+
default-pytest: ci-pytest
184+
185+
ci-pytest: all
186+
srcdir=$(srcdir) $(PYTEST) -v $(srcdir)/http
187+
180188
checksrc:
181189
(cd libtest && $(MAKE) checksrc)
182190
(cd unit && $(MAKE) checksrc)

tests/http/clients/CMakeLists.txt

+3
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
#
2323
###########################################################################
2424

25+
add_custom_target(test-http-clients)
26+
2527
# Get 'check_PROGRAMS' variable
2628
transform_makefile_inc("Makefile.inc" "${CMAKE_CURRENT_BINARY_DIR}/Makefile.inc.cmake")
2729
include("${CMAKE_CURRENT_BINARY_DIR}/Makefile.inc.cmake")
@@ -30,6 +32,7 @@ foreach(_target IN LISTS check_PROGRAMS)
3032
set(_target_name "curlt-client-${_target}")
3133
add_executable(${_target_name} EXCLUDE_FROM_ALL "${_target}.c")
3234
add_dependencies(testdeps ${_target_name})
35+
add_dependencies(test-http-clients ${_target_name})
3336
target_include_directories(${_target_name} PRIVATE
3437
"${CURL_BINARY_DIR}/lib" # for "curl_config.h"
3538
"${CURL_SOURCE_DIR}/lib" # for "curl_setup.h"

tests/http/conftest.py

-2
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,6 @@ def env(pytestconfig) -> Env:
7373
pytest.skip(env.incomplete_reason())
7474

7575
env.setup()
76-
if not env.make_clients():
77-
pytest.exit(1)
7876
return env
7977

8078
@pytest.fixture(scope="package", autouse=True)

tests/http/testenv/env.py

-9
Original file line numberDiff line numberDiff line change
@@ -579,12 +579,3 @@ def make_data_file(self, indir: str, fname: str, fsize: int,
579579
i = int(fsize / line_length) + 1
580580
fd.write(f"{i:09d}-{s}"[0:remain-1] + "\n")
581581
return fpath
582-
583-
def make_clients(self):
584-
client_dir = os.path.join(self.project_dir, 'tests/http/clients')
585-
p = subprocess.run(['make'], capture_output=True, text=True,
586-
cwd=client_dir)
587-
if p.returncode != 0:
588-
pytest.exit(f"`make`in {client_dir} failed:\n{p.stderr}")
589-
return False
590-
return True

0 commit comments

Comments
 (0)