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

tests(derived_code_mappings): Refactor the test a bit #86189

Merged
merged 1 commit into from
Mar 3, 2025

Conversation

armenzg
Copy link
Member

@armenzg armenzg commented Mar 3, 2025

Changes included:

  • Clearly show what frame is used within a specific test
  • Force-calling helper functions with keyword arguments

This forces writing tests by declaring frames within the test rather than having a list at the top of the class.
image

Changes included:

* Clearly show what frame is used within a specific test
* Force calling helper functions with keyword arguments
"""Helper function to prevent creating an event without a platform."""
test_data = {"platform": platform, "stacktrace": {"frames": frames}}
return self.store_event(data=test_data, project_id=self.project.id)
# XXX: In the future fix store_event to return the correct type
return cast(GroupEvent, self.store_event(data=test_data, project_id=self.project.id))
Copy link
Member Author

Choose a reason for hiding this comment

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

Returning a GroupEvent guarantees that group_id is always defined. Without this change, this line would complain with group_id not always being defined.
image

patch("sentry.utils.metrics.incr") as mock_incr,
):
process_event(self.project.id, self.event.group_id, self.event.event_id)
event = self.create_event(frames, platform)
Copy link
Member Author

Choose a reason for hiding this comment

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

This event creation used to happen here:
image

assert not RepositoryProjectPathConfig.objects.exists()
return code_mappings

def frame(self, filename: str, in_app: bool | None = True) -> dict[str, str | bool]:
Copy link
Member Author

Choose a reason for hiding this comment

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

New helper function. Not necessary but it helps shorten lines.

platform: str,
) -> list[CodeMapping]:
with patch(GET_TREES_FOR_ORG, return_value=self._get_trees_for_org(repo_files)):
event = self.create_event(frames, platform)
Copy link
Member Author

Choose a reason for hiding this comment

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

Creating the event here rather than in the setUp function.
image

{"in_app": True, "filename": "\\sentry\\dog\\cat\\parrot.py"},
{"in_app": True, "filename": "C:sentry\\tasks.py"},
{"in_app": True, "filename": "D:\\Users\\code\\sentry\\models\\release.py"},
]
Copy link
Member Author

Choose a reason for hiding this comment

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

Up until now, the frames would be defined at the class level rather than within the test.
The tests will now clearly state which of all frames will be in use (rather than the whole list defined here):
image

Copy link
Member Author

Choose a reason for hiding this comment

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

This PR now forces us to declare what frames are considered within each test rather than having a list at the top of the class.
image

@armenzg armenzg marked this pull request as ready for review March 3, 2025 14:28
@armenzg armenzg requested a review from a team as a code owner March 3, 2025 14:28
@armenzg armenzg enabled auto-merge (squash) March 3, 2025 14:28
@armenzg armenzg merged commit 946807f into master Mar 3, 2025
48 checks passed
@armenzg armenzg deleted the tests/code_mappings/armenzg branch March 3, 2025 19:15
@github-actions github-actions bot locked and limited conversation to collaborators Mar 22, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants