Skip to content

Commit b2e8446

Browse files
committed
Improve assert output on failure
* Failures where the assert happened in Clientrunner.assert_metadata where not handled as pytest verbose asserts: Fix this by registering the module for assert rewriting * assert on serialized metadata so that pytest assert gives us nice output * Increase verbosity in Makefile so it's at same level as the action Signed-off-by: Jussi Kukkonen <jkukkonen@google.com>
1 parent 8d252f7 commit b2e8446

File tree

3 files changed

+10
-9
lines changed

3 files changed

+10
-9
lines changed

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ fix: env/pyvenv.cfg
4949

5050
PHONY: test-python-tuf
5151
test-python-tuf: dev
52-
./env/bin/pytest tuf_conformance \
52+
./env/bin/pytest -v tuf_conformance \
5353
--entrypoint "./env/bin/python ./clients/python-tuf/python_tuf.py" \
5454
--repository-dump-dir $(DUMP_DIR)
5555
@echo Repository dump in $(DUMP_DIR)
@@ -60,7 +60,7 @@ test-python-tuf: dev
6060

6161
PHONY: test-go-tuf
6262
test-go-tuf: dev build-go-tuf
63-
./env/bin/pytest tuf_conformance \
63+
./env/bin/pytest -v tuf_conformance \
6464
--entrypoint "./clients/go-tuf/go-tuf" \
6565
--repository-dump-dir $(DUMP_DIR)
6666
@echo Repository dump in $(DUMP_DIR)

tuf_conformance/__init__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,6 @@
1+
import pytest
2+
13
__version__ = "2.1.0"
4+
5+
# register pytest asserts before the imports happen in conftest.py
6+
pytest.register_assert_rewrite("tuf_conformance.client_runner")

tuf_conformance/client_runner.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
from tuf.api.exceptions import StorageError
77
from tuf.api.metadata import Metadata
8+
from tuf.api.serialization.json import JSONSerializer
89

910
from tuf_conformance.metadata import MetadataTest
1011
from tuf_conformance.simulator_server import (
@@ -130,13 +131,8 @@ def assert_metadata(self, role: str, expected_bytes: bytes | None) -> None:
130131
try:
131132
trusted = MetadataTest.from_file(
132133
os.path.join(self.metadata_dir, f"{role}.json")
133-
)
134+
).to_bytes(JSONSerializer())
134135
except StorageError:
135136
trusted = None
136137

137-
if expected_bytes is not None:
138-
expected = Metadata.from_bytes(expected_bytes)
139-
else:
140-
expected = None
141-
142-
assert trusted == expected, f"Unexpected trusted role {role} content"
138+
assert trusted == expected_bytes, f"Unexpected trusted role {role} content"

0 commit comments

Comments
 (0)