Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions docs/developer/testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -225,10 +225,12 @@ def test_dynflow_service_instances(server, instance):

## Where to add new tests

The directory `tests/feature` is special. Any subdirectory automatically applies the feature marker. `tests/feature/foreman/api_test.py` is equivalent to `tests/foreman_api_test.py` with `pytestmark = pytest.mark.feature("foreman")`.

| What you're testing | File |
| --- | --- |
| A new service (container or systemd unit) | `tests/<service>_test.py` |
| Foreman API behavior | `tests/foreman_api_test.py` (or a new file for larger areas) |
| A new service (container or systemd unit) | `tests/feature/<feature>/<service>_test.py` |
| Foreman API behavior | `tests/feature/foreman/api_test.py` (or a new file for larger areas) |
| Client registration or content workflows | `tests/client_test.py` |
| CLI flags, playbooks, or feature management | `tests/features_test.py` or `tests/playbooks_test.py` |
| A standalone script (no deployment needed) | `tests/unit/<name>_test.py` |
Expand Down
13 changes: 13 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,19 @@ def pytest_configure(config):
config.user_parameters = UserParameters(config)


def pytest_collection_modifyitems(config, items):
feature_dir = config.rootdir / 'tests' / 'feature'
for item in items:
try:
rel_path = item.path.relative_to(feature_dir)
except ValueError:
# Not in the features directory
pass
else:
feature = rel_path.parts[0]
item.add_marker(pytest.mark.feature(feature))
Comment thread
ehelms marked this conversation as resolved.


def pytest_runtest_setup(item):
feature_markers = set(mark.args[0] for mark in item.iter_markers(name="feature"))
if feature_markers:
Expand Down
Empty file added tests/feature/__init__.py
Empty file.
Empty file.
File renamed without changes.
Empty file.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Empty file.
File renamed without changes.
File renamed without changes.
2 changes: 0 additions & 2 deletions tests/iop/images_test.py → tests/feature/iop/images_test.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import pytest

pytestmark = pytest.mark.feature("iop")

IOP_IMAGES = [
"iop-kafka",
"iop-ingress",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
import pytest

pytestmark = pytest.mark.feature("iop")


def test_advisor_backend_api_service(server):
service = server.service("iop-service-advisor-backend-api")
assert service.is_running
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
import pytest

pytestmark = pytest.mark.feature("iop")


def test_advisor_frontend_assets_directory(server):
assets_dir = server.file("/var/www/iop/assets/apps/advisor")
assert assets_dir.exists
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
import pytest

pytestmark = pytest.mark.feature("iop")


def test_cvemap_download_script(server):
script = server.file("/usr/local/bin/iop-cvemap-download.sh")
assert script.exists
Expand Down
5 changes: 0 additions & 5 deletions tests/iop/test_engine.py → tests/feature/iop/test_engine.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
import pytest

pytestmark = pytest.mark.feature("iop")


def test_engine_service(server):
service = server.service("iop-core-engine")
assert service.is_running
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
import pytest

pytestmark = pytest.mark.feature("iop")


def test_gateway_service(server):
service = server.service("iop-core-gateway")
assert service.is_running
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
import pytest

pytestmark = pytest.mark.feature("iop")


def test_ingress_service(server):
service = server.service("iop-core-ingress")
assert service.is_running
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
import pytest

pytestmark = pytest.mark.feature("iop")


def test_iop_core_kafka_service(server):
service = server.service("iop-core-kafka")
assert service.is_running
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
import pytest

pytestmark = pytest.mark.feature("iop")


def test_inventory_migrate_service(server):
service = server.service("iop-core-host-inventory-migrate")
assert service.is_enabled
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
import pytest

pytestmark = pytest.mark.feature("iop")


def test_inventory_frontend_assets_directory(server):
assets_dir = server.file("/var/www/iop/assets/apps/inventory")
assert assets_dir.exists
Expand Down
5 changes: 0 additions & 5 deletions tests/iop/test_kafka.py → tests/feature/iop/test_kafka.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
import pytest

pytestmark = pytest.mark.feature("iop")


def test_kafka_service(server):
service = server.service("iop-core-kafka")
assert service.is_running
Expand Down
5 changes: 0 additions & 5 deletions tests/iop/test_puptoo.py → tests/feature/iop/test_puptoo.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
import pytest

pytestmark = pytest.mark.feature("iop")


def test_puptoo_service(server):
service = server.service("iop-core-puptoo")
assert service.is_running
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
import pytest

pytestmark = pytest.mark.feature("iop")


def test_remediation_api_service(server):
service = server.service("iop-service-remediations-api")
assert service.is_running
Expand Down
5 changes: 0 additions & 5 deletions tests/iop/test_vmaas.py → tests/feature/iop/test_vmaas.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
import pytest

pytestmark = pytest.mark.feature("iop")


def test_vmaas_reposcan_service(server):
service = server.service("iop-service-vmaas-reposcan")
assert service.is_running
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
import pytest

pytestmark = pytest.mark.feature("iop")


def test_vulnerability_manager_service(server):
service = server.service("iop-service-vuln-manager")
assert service.is_running
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
import pytest

pytestmark = pytest.mark.feature("iop")


def test_vulnerability_frontend_assets_directory(server):
assets_dir = server.file("/var/www/iop/assets/apps/vulnerability")
assert assets_dir.exists
Expand Down
5 changes: 0 additions & 5 deletions tests/iop/test_yuptoo.py → tests/feature/iop/test_yuptoo.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
import pytest

pytestmark = pytest.mark.feature("iop")


def test_yuptoo_service(server):
service = server.service("iop-core-yuptoo")
assert service.is_running
Expand Down
Loading