Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow custom metadata for replay file #82

Merged

Conversation

marcelotrevisani
Copy link
Contributor

Allow custom metadata in replay files

Refactor replay metadata handling with dataclasses. Introduced ReplayTestMetadata dataclass for cleaner metadata management. Updated serialization and deserialization logic to use the new dataclass. Added new tests to validate metadata handling and functionality.

Closes #78

Refactor replay metadata handling with dataclasses. Introduced `ReplayTestMetadata` dataclass for cleaner metadata management. Updated serialization and deserialization logic to use the new dataclass. Added new tests to validate metadata handling and functionality.
Replaced PEP 604 union syntax (|) with Optional for type hints to maintain compatibility with Python versions earlier than 3.10.
@marcelotrevisani marcelotrevisani force-pushed the feature/custom-metadata-replay-file branch from ad55871 to a0dae93 Compare February 3, 2025 21:41
@marcelotrevisani
Copy link
Contributor Author

that is ready for review please
@nicoddemus @tadeu @prusse-martin

Copy link
Member

@nicoddemus nicoddemus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work!

Left some comments, please take a look.

README.rst Show resolved Hide resolved
src/pytest_replay/__init__.py Outdated Show resolved Hide resolved
src/pytest_replay/__init__.py Outdated Show resolved Hide resolved
src/pytest_replay/__init__.py Outdated Show resolved Hide resolved
tests/test_replay.py Outdated Show resolved Hide resolved
Comment on lines 145 to 148
node_metadata = json.loads(stripped)
nodeid = node_metadata["nodeid"]
if "finish" in node_metadata:
self.nodes[nodeid] = ReplayTestMetadata(**node_metadata)
Copy link
Member

@prusse-martin prusse-martin Feb 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe that if somehow the test crashes before the finish you metadata would no be save, but it could be relevant to the crash reproduction.

You possible want to emit to the replay file "update metadata" instructions so they could be loaded back to reproduce the problem.
Something in the lines of:

{"nodeid": "test_1.py::test_bar", "start": 3.0}
{"nodeid": "test_1.py::test_bar", "start": 3.0, "metadata": {"a": "asd"}}
{"nodeid": "test_1.py::test_bar", "start": 3.0, "metadata": {"a": "asd", "b": 7}}
{"nodeid": "test_1.py::test_bar", "start": 3.0, "metadata": {"a": "asd", "b": 7}, "finish": 4.0, "outcome": "passed"}

There we see the metadata evolving.

And probably could help pinpoint the crash source if the output is just:

{"nodeid": "test_1.py::test_bar", "start": 3.0}
{"nodeid": "test_1.py::test_bar", "start": 3.0, "metadata": {"a": "asd"}}

(a crash cause some lines to not be present)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the feedback! You're absolutely right, and this is something I already noted in the issue under "Limitations". In my specific scenario, it's quite rare for tests to crash, they usually just fail, so the current approach works well enough for my use case. However, I do see the value in capturing incremental metadata.
To fully address this broader scenario, we'd likely need to track all setups and all teardowns associated with a test, ensuring the metadata reflects each setup and teardown, since a crash could happen at any point.

For now, I’d prefer to move forward with the current implementation, but I completely agree that your suggestion would be the ideal enhancement. It’s definitely something worth considering for future improvements! Maybe, could you create an issue about it so we can tackle that in the future or when someone sees values in it please?

marcelotrevisani and others added 2 commits February 4, 2025 22:25
Co-authored-by: Bruno Oliveira <[email protected]>
@marcelotrevisani
Copy link
Contributor Author

Great work!

Left some comments, please take a look.

Thank you for your feedback!

I have addressed all your comments in the review, could you please take a second look? Thanks!

Copy link
Member

@nicoddemus nicoddemus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, thanks!

After @prusse-martin's approval we can make a new release.

@nicoddemus nicoddemus merged commit 368466f into ESSS:master Feb 5, 2025
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow Custom Data in Replay Files
3 participants