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

breaking(pytest_plugins/operator_groups): Raise exception if test missing group number #113

Merged
merged 3 commits into from
Dec 12, 2023

Conversation

carlcsaposs-canonical
Copy link
Contributor

Fixes #106

If a test is missing a group number, it is almost certainly a mistake instead of intentional. Previously, if the test was missing a group number, it was marked as skipped (which will cause the job to pass on GitHub CI).

…sing group number

Fixes #106

If a test is missing a group number, it is almost certainly a mistake instead of intentional. Previously, if the test was missing a group number, it was marked as skipped (which will cause the job to pass on GitHub CI).
@carlcsaposs-canonical
Copy link
Contributor Author

carlcsaposs-canonical commented Dec 11, 2023

tested on canonical/mysql-operator#370

@@ -60,7 +60,9 @@ class Group:
groups: set[Group] = set()
for function in items:
if (group_number := _get_group_number(function)) is None:
continue
raise Exception(

Choose a reason for hiding this comment

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

What if we add a fallback value + a deprecation warning instead?
So it allow a more gentle adoption.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That defeats the whole point—the change in this PR is to fail loudly instead of quietly skipping the test

Copy link
Contributor Author

Choose a reason for hiding this comment

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

FYI this change doesn't break anyone not using the pytest_operator_groups plugin

Choose a reason for hiding this comment

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

My point was not to skip the test silently, but to fallback to something, let's say group 1 with the addition of a loud warning.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, I see

I was also thinking about adding that

My concern is that inferring the group number could get a bit too magical and make it difficult to debug

For example, if you add a new test at the end of a file with 2 test groups and forget a group number, it will be added to group 1. Without the plugin, the behavior with pytest-operator is to run the tests sequentially. Many of our tests are written in a way that assumes execution order (e.g. assumes that cluster is deployed). However, if you forget the group number, it will break developer's existing expectations about test ordering and run before any tests in group 2

IMO maybe still worth considering as a separate issue/PR

Regardless, I think this PR is an improvement on the current behavior (quietly skip tests)

Choose a reason for hiding this comment

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

Can't disagree

Copy link

@taurus-forever taurus-forever left a comment

Choose a reason for hiding this comment

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

IMHO Fail-fast is a good fix for "silently miss test".
Can be improved further as an enhancement and this is a bugfix, IMHO.

@carlcsaposs-canonical carlcsaposs-canonical merged commit 6739c63 into main Dec 12, 2023
1 check passed
@carlcsaposs-canonical carlcsaposs-canonical deleted the group-collect-error branch December 12, 2023 12:23
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.

Consider raising error if all tests in Python module are missing group mark
3 participants