Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
Serialization hooks #4965
Serialization hooks #4965
Changes from 8 commits
0c63f99
7b9a414
d856f4e
f2e0c74
6457742
e4eec34
ceef0af
2d77018
9311d82
65c8e8a
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
heh neat,
testify
used the same approach: https://github.com/Yelp/Testify/blob/335f04a7de583026a1e0d04d006f4c40524fd89d/testify/test_discovery.py#L57-L59I think this oddity could really be purged if tests were required to be defined in the module they appear in, and then importing names wouldn't add them to discovery -- always was a weird thing about
unittest
in my mind -- fwiw I ensured that in testify with this codeThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick: these implementations don't actually serialize/unserialize the objects: they convert them to/from native Python types which can be serialised/deserialised as JSON. Serialisation, to my mind, means converting something to bytes (or at least str).
That's a fine API if that's what you want, but maybe the names should reflect it. Sorry for bikeshedding. ;-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not at all, thanks for chipping in. I agree with you, they are not actually serializing anything.
I'm fine with changing those names now, easier to do this before merging. Do you have a suggestion?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe
pytest_report_to_json
andpytest_report_from_json
? It's not strictly accurate either, because they're producing dicts suitable for JSON, not actual JSON, but I think that inaccuracy is widely accepted.Otherwise:
pytest_report_to_dict
- accurate but less specificpytest_report_to_jsonable
- kind of ugly, IMOThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would like to avoid restricting this to "json", because we might change the actual representation to something else.
I like
pytest_report_to_dict
andpytest_report_from_dict
; I agree it is less accurate, but I believe it is enough to mention that it only supports built-in types in the docs.Thanks a lot for the input! I will change to
pytest_report_to_dict
andpytest_report_from_dict
later then. 👍There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
at $previous_job we called this
def __primitive__(self):
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
JSON-compatible is a stricter standard than built-in types (e.g. no sets in JSON), but so long as the requirements are documented, I think the
dict
naming is a good option.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about
…_to_python
and…_from_python
? But it does not clearly indicate the overall direction (as with…serialize
and…unserialize
).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
to/from_serializable
just to keep the door open for msgpack and yaml as wellThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like @RonnyPfannschmidt's, we describe the intent rather what the hook returns in detail. 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done,
pytest_report_from_serializable
/pytest_report_to_serializable
. 👍If nobody objects I will merge this later then.