-
Notifications
You must be signed in to change notification settings - Fork 252
Initial backend for Next Gen #426
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
Merged
Merged
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| import json | ||
| from typing import Any | ||
| from typing import Dict | ||
|
|
||
| import pytest | ||
|
|
||
|
|
||
| class NextGenReport: | ||
| def __init__(self, config, data_file): | ||
| self._config = config | ||
| self._data_file = data_file | ||
|
|
||
| self._title = "Next Gen Report" | ||
| self._data = { | ||
| "title": self._title, | ||
| "collectedItems": 0, | ||
| "environment": {}, | ||
| "tests": [], | ||
| } | ||
|
|
||
| self._data_file.parent.mkdir(parents=True, exist_ok=True) | ||
|
|
||
| def _write(self): | ||
| try: | ||
| data = json.dumps(self._data) | ||
| except TypeError: | ||
| data = cleanup_unserializable(self._data) | ||
| data = json.dumps(data) | ||
|
|
||
| with self._data_file.open("w", buffering=1, encoding="UTF-8") as f: | ||
| f.write("const jsonData = ") | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can we combine these |
||
| f.write(data) | ||
| f.write("\n") | ||
|
|
||
| @pytest.hookimpl(trylast=True) | ||
| def pytest_sessionstart(self, session): | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wouldn't all the |
||
| config = session.config | ||
| if hasattr(config, "_metadata") and config._metadata: | ||
| metadata = config._metadata | ||
| self._data["environment"] = metadata | ||
| self._write() | ||
|
|
||
| @pytest.hookimpl(trylast=True) | ||
| def pytest_collection_finish(self, session): | ||
| self._data["collectedItems"] = len(session.items) | ||
| self._write() | ||
|
|
||
| @pytest.hookimpl(trylast=True) | ||
| def pytest_runtest_logreport(self, report): | ||
| data = self._config.hook.pytest_report_to_serializable( | ||
| config=self._config, report=report | ||
| ) | ||
| self._data["tests"].append(data) | ||
| self._write() | ||
|
|
||
|
|
||
| def cleanup_unserializable(d: Dict[str, Any]) -> Dict[str, Any]: | ||
| """Return new dict with entries that are not json serializable by their str().""" | ||
| result = {} | ||
| for k, v in d.items(): | ||
| try: | ||
| json.dumps({k: v}) | ||
| except TypeError: | ||
| v = str(v) | ||
| result[k] = v | ||
| return result | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
This comment was marked as outdated.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
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.
I opened an issue to track typing (#434)
I also added mypy to our linting target and began work on typing the project in #435