From 382073db78adaff679cdab055fe7a71804e7f469 Mon Sep 17 00:00:00 2001 From: Marco Mariani Date: Mon, 17 Apr 2023 16:52:10 +0200 Subject: [PATCH] CI: Run pytest sequentially, clean up test markers --- .github/workflows/docker-tests.yml | 2 +- Makefile | 7 ++++++- docker/test/pytest-debug.ini | 6 ------ docker/test/pytest.ini | 10 ++++++++-- docker/test/tests/conftest.py | 17 ----------------- docker/test/tests/test_agent.py | 4 ---- docker/test/tests/test_agent_only.py | 4 ---- docker/test/tests/test_bouncer.py | 4 ---- docker/test/tests/test_capi.py | 3 --- docker/test/tests/test_cold_logs.py | 4 ---- docker/test/tests/test_flavors.py | 4 ---- docker/test/tests/test_hello.py | 4 ---- docker/test/tests/test_hub.py | 4 ---- docker/test/tests/test_hub_collections.py | 3 --- docker/test/tests/test_hub_parsers.py | 4 ---- docker/test/tests/test_hub_postoverflows.py | 2 -- docker/test/tests/test_hub_scenarios.py | 4 ---- docker/test/tests/test_local_api_url.py | 2 -- docker/test/tests/test_metrics.py | 2 -- docker/test/tests/test_nolapi.py | 4 ---- docker/test/tests/test_simple.py | 4 ---- docker/test/tests/test_tls.py | 4 ---- docker/test/tests/test_version.py | 4 ---- docker/test/tests/test_wal.py | 4 ---- 24 files changed, 15 insertions(+), 95 deletions(-) delete mode 100644 docker/test/pytest-debug.ini diff --git a/.github/workflows/docker-tests.yml b/.github/workflows/docker-tests.yml index 6476d9f0a..dec87a3f3 100644 --- a/.github/workflows/docker-tests.yml +++ b/.github/workflows/docker-tests.yml @@ -112,4 +112,4 @@ jobs: CROWDSEC_TEST_TIMEOUT: 90 run: | cd docker/test - pipenv run pytest -n 2 --durations=0 --color=yes + pipenv run pytest -n 1 --durations=0 --color=yes diff --git a/Makefile b/Makefile index 373a5995e..52f8ab7c6 100644 --- a/Makefile +++ b/Makefile @@ -63,9 +63,14 @@ all: clean test build .PHONY: plugins plugins: http-plugin slack-plugin splunk-plugin email-plugin dummy-plugin +# same as "$(MAKE) -f debian/rules clean" but without the dependency on debhelper .PHONY: clean-debian clean-debian: - $(MAKE) -f debian/rules clean + @$(RM) -r debian/crowdsec + @$(RM) -r debian/files + @$(RM) -r debian/.debhelper + @$(RM) -r debian/*.substvars + @$(RM) -r debian/*-stamp .PHONY: clean clean: clean-test diff --git a/docker/test/pytest-debug.ini b/docker/test/pytest-debug.ini deleted file mode 100644 index ce3c9173a..000000000 --- a/docker/test/pytest-debug.ini +++ /dev/null @@ -1,6 +0,0 @@ -[pytest] -# run all tests sequentially, drop to pdb on first failure -addopts = -n 0 --no-header --pdb --pdbcls=IPython.terminal.debugger:Pdb -env_files = - .env - default.env diff --git a/docker/test/pytest.ini b/docker/test/pytest.ini index 94f8d3ae8..8400efa7c 100644 --- a/docker/test/pytest.ini +++ b/docker/test/pytest.ini @@ -1,7 +1,13 @@ [pytest] -# run all tests in parallel, compact output -addopts = -n 4 --no-header -m "not (deb or rpm)" required_plugins = pytest-xdist +addopts = + --pdbcls=IPython.terminal.debugger:Pdb + --strict-markers + -m "not (deb or rpm)" + -n auto +markers: + deb: tests for .deb packaging + rpm: tests for .rpm packaging env_files = .env default.env diff --git a/docker/test/tests/conftest.py b/docker/test/tests/conftest.py index 93131fe68..e69de29bb 100644 --- a/docker/test/tests/conftest.py +++ b/docker/test/tests/conftest.py @@ -1,17 +0,0 @@ - -pytest_plugins = ("cs",) - - -def pytest_configure(config): - config.addinivalue_line( - 'markers', 'deb: tests for build/install/configure a debian packages' - ) - config.addinivalue_line( - 'markers', 'rpm: tests for build/install/configure rpm packages' - ) - config.addinivalue_line( - 'markers', 'docker: mark tests for lone or manually orchestrated containers' - ) - config.addinivalue_line( - 'markers', 'compose: mark tests for docker compose projects' - ) diff --git a/docker/test/tests/test_agent.py b/docker/test/tests/test_agent.py index e1ede3f89..3db635488 100644 --- a/docker/test/tests/test_agent.py +++ b/docker/test/tests/test_agent.py @@ -2,10 +2,6 @@ from http import HTTPStatus -import pytest - -pytestmark = pytest.mark.docker - def test_no_agent(crowdsec, flavor): """Test DISABLE_AGENT=true""" diff --git a/docker/test/tests/test_agent_only.py b/docker/test/tests/test_agent_only.py index d9db3ca30..2ff0a0365 100644 --- a/docker/test/tests/test_agent_only.py +++ b/docker/test/tests/test_agent_only.py @@ -3,10 +3,6 @@ from http import HTTPStatus import random -import pytest - -pytestmark = pytest.mark.docker - def test_split_lapi_agent(crowdsec, flavor): rand = str(random.randint(0, 10000)) diff --git a/docker/test/tests/test_bouncer.py b/docker/test/tests/test_bouncer.py index 1324c3bd3..9dcfb140b 100644 --- a/docker/test/tests/test_bouncer.py +++ b/docker/test/tests/test_bouncer.py @@ -8,10 +8,6 @@ import hashlib from http import HTTPStatus import json -import pytest - -pytestmark = pytest.mark.docker - def hex512(s): """Return the sha512 hash of a string as a hex string""" diff --git a/docker/test/tests/test_capi.py b/docker/test/tests/test_capi.py index 08b3a7047..660c89aab 100644 --- a/docker/test/tests/test_capi.py +++ b/docker/test/tests/test_capi.py @@ -2,9 +2,6 @@ from http import HTTPStatus -import pytest -pytestmark = pytest.mark.docker - def test_no_capi(crowdsec, flavor): """Test no CAPI (disabled by default in tests)""" diff --git a/docker/test/tests/test_cold_logs.py b/docker/test/tests/test_cold_logs.py index 6f6c578eb..6a1b07d90 100644 --- a/docker/test/tests/test_cold_logs.py +++ b/docker/test/tests/test_cold_logs.py @@ -4,10 +4,6 @@ import datetime from pytest_cs import Status -import pytest - -pytestmark = pytest.mark.docker - def test_cold_logs(crowdsec, tmp_path_factory, flavor): env = { diff --git a/docker/test/tests/test_flavors.py b/docker/test/tests/test_flavors.py index c6aba888d..c233c082c 100644 --- a/docker/test/tests/test_flavors.py +++ b/docker/test/tests/test_flavors.py @@ -6,10 +6,6 @@ Test basic behavior of all the image variants from http import HTTPStatus -import pytest - -pytestmark = pytest.mark.docker - def test_cscli_lapi(crowdsec, flavor): """Test if cscli can talk to lapi""" diff --git a/docker/test/tests/test_hello.py b/docker/test/tests/test_hello.py index a21fde850..e792d269d 100644 --- a/docker/test/tests/test_hello.py +++ b/docker/test/tests/test_hello.py @@ -6,10 +6,6 @@ Smoke tests in case docker is not set up correctly or has connection issues. import subprocess -import pytest - -pytestmark = pytest.mark.docker - def test_docker_cli_run(): """Test if docker run works from the command line. Capture stdout too""" diff --git a/docker/test/tests/test_hub.py b/docker/test/tests/test_hub.py index 2365e3a9c..35e1a2b11 100644 --- a/docker/test/tests/test_hub.py +++ b/docker/test/tests/test_hub.py @@ -7,10 +7,6 @@ Test pre-installed hub items. from http import HTTPStatus import json -import pytest - -pytestmark = pytest.mark.docker - def test_preinstalled_hub(crowdsec, flavor): """Test hub objects installed in the entrypoint""" diff --git a/docker/test/tests/test_hub_collections.py b/docker/test/tests/test_hub_collections.py index 81567954b..f105e49b6 100644 --- a/docker/test/tests/test_hub_collections.py +++ b/docker/test/tests/test_hub_collections.py @@ -9,11 +9,8 @@ import json import os import pwd -import pytest import yaml -pytestmark = pytest.mark.docker - def test_install_two_collections(crowdsec, flavor): """Test installing collections at startup""" diff --git a/docker/test/tests/test_hub_parsers.py b/docker/test/tests/test_hub_parsers.py index 8cfaeecf9..9b8179e21 100644 --- a/docker/test/tests/test_hub_parsers.py +++ b/docker/test/tests/test_hub_parsers.py @@ -7,10 +7,6 @@ Test parser management from http import HTTPStatus import json -import pytest - -pytestmark = pytest.mark.docker - def test_install_two_parsers(crowdsec, flavor): """Test installing parsers at startup""" diff --git a/docker/test/tests/test_hub_postoverflows.py b/docker/test/tests/test_hub_postoverflows.py index 80fdbc2b7..fa16a3226 100644 --- a/docker/test/tests/test_hub_postoverflows.py +++ b/docker/test/tests/test_hub_postoverflows.py @@ -8,8 +8,6 @@ from http import HTTPStatus import json import pytest -pytestmark = pytest.mark.docker - def test_install_two_postoverflows(crowdsec, flavor): """Test installing postoverflows at startup""" diff --git a/docker/test/tests/test_hub_scenarios.py b/docker/test/tests/test_hub_scenarios.py index a60ede667..a4accde0b 100644 --- a/docker/test/tests/test_hub_scenarios.py +++ b/docker/test/tests/test_hub_scenarios.py @@ -7,10 +7,6 @@ Test scenario management from http import HTTPStatus import json -import pytest - -pytestmark = pytest.mark.docker - def test_install_two_scenarios(crowdsec, flavor): """Test installing scenarios at startup""" diff --git a/docker/test/tests/test_local_api_url.py b/docker/test/tests/test_local_api_url.py index 262e8fbef..ae025d13a 100644 --- a/docker/test/tests/test_local_api_url.py +++ b/docker/test/tests/test_local_api_url.py @@ -4,8 +4,6 @@ from http import HTTPStatus import pytest -pytestmark = pytest.mark.docker - def test_local_api_url_default(crowdsec, flavor): """Test LOCAL_API_URL (default)""" diff --git a/docker/test/tests/test_metrics.py b/docker/test/tests/test_metrics.py index 8a6d53181..ab7b559a1 100644 --- a/docker/test/tests/test_metrics.py +++ b/docker/test/tests/test_metrics.py @@ -4,8 +4,6 @@ from http import HTTPStatus import pytest -pytestmark = pytest.mark.docker - def test_metrics_port_default(crowdsec, flavor): """Test metrics""" diff --git a/docker/test/tests/test_nolapi.py b/docker/test/tests/test_nolapi.py index 6edb354fe..62e40dc26 100644 --- a/docker/test/tests/test_nolapi.py +++ b/docker/test/tests/test_nolapi.py @@ -2,10 +2,6 @@ from pytest_cs import Status -import pytest - -pytestmark = pytest.mark.docker - def test_no_agent(crowdsec, flavor): """Test DISABLE_LOCAL_API=true (failing stand-alone container)""" diff --git a/docker/test/tests/test_simple.py b/docker/test/tests/test_simple.py index 951d8be4b..faa693f28 100644 --- a/docker/test/tests/test_simple.py +++ b/docker/test/tests/test_simple.py @@ -1,9 +1,5 @@ #!/usr/bin/env python -import pytest - -pytestmark = pytest.mark.docker - # XXX this is redundant, already tested in pytest_cs def test_crowdsec(crowdsec, flavor): diff --git a/docker/test/tests/test_tls.py b/docker/test/tests/test_tls.py index cea29b9fc..08bd8ab1c 100644 --- a/docker/test/tests/test_tls.py +++ b/docker/test/tests/test_tls.py @@ -8,10 +8,6 @@ import random from pytest_cs import Status -import pytest - -pytestmark = pytest.mark.docker - def test_missing_key_file(crowdsec, flavor): """Test that cscli and agent can communicate to LAPI with TLS""" diff --git a/docker/test/tests/test_version.py b/docker/test/tests/test_version.py index c152d2e4e..f49a278da 100644 --- a/docker/test/tests/test_version.py +++ b/docker/test/tests/test_version.py @@ -1,9 +1,5 @@ #!/usr/bin/env python -import pytest - -pytestmark = pytest.mark.docker - def test_version_docker_platform(crowdsec, flavor): with crowdsec(flavor=flavor) as cs: diff --git a/docker/test/tests/test_wal.py b/docker/test/tests/test_wal.py index e3edbcaf3..8adf43a97 100644 --- a/docker/test/tests/test_wal.py +++ b/docker/test/tests/test_wal.py @@ -2,10 +2,6 @@ from http import HTTPStatus -import pytest - -pytestmark = pytest.mark.docker - def test_use_wal_default(crowdsec, flavor): """Test USE_WAL default"""