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

[RHELC-1293] Introduce pre-commit hook to register custom markers #1018

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

danmyway
Copy link
Member

@danmyway danmyway commented Dec 13, 2023

  • Registering the custom markers is oftentimes tedious and can lead to oversight when registering a new marker or removing a deprecated one
  • this should ensure, that the configuration stays up-to-date with changes in existing markers

Jira Issues: RHELC-1293

Checklist

  • PR has been tested manually in a VM (either author or reviewer)
  • Jira issue has been made public if possible
  • [RHELC-] is part of the PR title
  • GitHub label has been added to help with Release notes
  • PR title explains the change from the user's point of view
  • Code and tests are documented properly
  • The commits are squashed to as few commits as possible (without losing data)
  • When merged: Jira issue has been updated to Release Pending if relevant

* Registering the custom markers is oftentimes tedious and can lead to
  oversight when registering a new marker or removing a deprecated one
* this should ensure, that the configuration stays up-to-date with changes in existing markers

Signed-off-by: Daniel Diblik <ddiblik@redhat.com>
@danmyway danmyway added no-changelog If it should be excluded from changelog or Release notes. Such as infra, reverted PRs, etc. tests-skip This PR does not require integration tests to be run. labels Dec 13, 2023
@has-bot
Copy link
Member

has-bot commented Dec 13, 2023

This PR does not require integration tests to be run.


@oamg/conversions-qe please review results and provide ack.

Copy link

codecov bot commented Dec 13, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (b31b46e) 94.25% compared to head (8307b5f) 94.25%.
Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1018   +/-   ##
=======================================
  Coverage   94.25%   94.25%           
=======================================
  Files          47       47           
  Lines        4526     4526           
  Branches      808      808           
=======================================
  Hits         4266     4266           
  Misses        183      183           
  Partials       77       77           
Flag Coverage Δ
centos-linux-7 89.38% <ø> (ø)
centos-linux-8 90.41% <ø> (ø)
centos-linux-9 90.47% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

return custom_markers


def update_pytest_ini(custom_markers, ini_file="pytest.ini"):
Copy link
Member

Choose a reason for hiding this comment

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

Since it's a ini file, maybe you could use the configparser module to deal with it? https://docs.python.org/3/library/configparser.html

"""
markers = set()
# Regex to match the pytest markers
marker_pattern = re.compile(r"@pytest\.mark\.(?P<marker>\w+)\(?")
Copy link
Member

Choose a reason for hiding this comment

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

^@pytest\.mark\.(\w)+ should be good enough

Comment on lines +51 to +54

ini_startswith = '[pytest]\ntestpaths = "convert2rhel/unit_tests"\nmarkers =\n'
with open(ini_file, "w", encoding="utf-8") as f:
if custom_markers:
Copy link
Member

Choose a reason for hiding this comment

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

I would move the condition to the beginning of the function:

Suggested change
ini_startswith = '[pytest]\ntestpaths = "convert2rhel/unit_tests"\nmarkers =\n'
with open(ini_file, "w", encoding="utf-8") as f:
if custom_markers:
if custom_markers:
# Nothing to do
return
ini_startswith = '[pytest]\ntestpaths = "convert2rhel/unit_tests"\nmarkers =\n'
with open(ini_file, "w", encoding="utf-8") as f:

@Venefilyn
Copy link
Member

Can we use this instead? Means we can get rid of a lot of the integration test specific markers (and just update the naming scheme of it)
https://docs.pytest.org/en/latest/example/markers.html#automatically-adding-markers-based-on-test-names

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
no-changelog If it should be excluded from changelog or Release notes. Such as infra, reverted PRs, etc. tests-skip This PR does not require integration tests to be run.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants