Skip to content

test: improve git isolation and fixes test missing a repository #647

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 1 commit into from
Jan 5, 2023

Conversation

noirbizarre
Copy link
Member

@noirbizarre noirbizarre commented Dec 30, 2022

Description

This PR follows #638 and extend the isolation to any GIT_ prefixed variables. It also ensure that every test requiring a tmp_git_project or tmp_commitizen_project fixture has it, even for test expecting a failure (to ensure the proper failure).

This fixes some false negatives in pre-commit as well as ordering side-effects for tests that were missing the fixture like this build failing on some totally unrelated (and untouched) cases.

There is few misc fixes and redundancy removal (lots of unnecessary nested .as_cwd() calls as well as some fixtures extracted into @pytest.mark.usefixtures() when not used in the test but still requiring the fixture setup))

Checklist

  • Add test cases to all the changes you introduce (N/A)
  • Run ./scripts/format and ./scripts/test locally to ensure this change passes linter check and test
  • Test the changes on the local machine manually
  • Update the documentation for the changes (N/A)

@noirbizarre noirbizarre mentioned this pull request Dec 30, 2022
4 tasks
@codecov
Copy link

codecov bot commented Dec 30, 2022

Codecov Report

❗ No coverage uploaded for pull request base (v3@5dfa0ef). Click here to learn what that means.
Patch has no changes to coverable lines.

Additional details and impacted files
@@          Coverage Diff          @@
##             v3     #647   +/-   ##
=====================================
  Coverage      ?   98.42%           
=====================================
  Files         ?       39           
  Lines         ?     1650           
  Branches      ?        0           
=====================================
  Hits          ?     1624           
  Misses        ?       26           
  Partials      ?        0           
Flag Coverage Δ
unittests 98.42% <0.00%> (?)

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

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

Copy link
Member

@Lee-W Lee-W left a comment

Choose a reason for hiding this comment

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

Just one minor question. I think this one is almost ready to merge

@noirbizarre
Copy link
Member Author

noirbizarre commented Dec 31, 2022

Yes, #638 was using a temporary GIT_CONFIG_GLOBAL ensuring the clean configuration.
This PR extends the isolation to all GIT_ environment variables because some settings can be defined by both the configuration file and the environment.
pre-commit is interfering with some of those, the git command is also exporting some depending on the version you use (see: https://github.com/pre-commit/pre-commit/blob/1f59f4cba8241ed7e572a1b5818bba74c6f31181/pre_commit/git.py#L27-L48), your shell can export some, your custom promt too, github actions can set some...
That's why without isolation you may have different behavior and some false negative depending on wether you are running in pre-commit or not, depending on your pre-commit version, depending on your git version, or depending of your own custom shell...
With this change, you ensure consistent and reproducible behavior on all environments, they always run with the minimal configuration (author and email) and no setting defined outside of the test case

@Lee-W
Copy link
Member

Lee-W commented Jan 5, 2023

@noirbizarre Cool! many thanks for the detailed explanation!

@Lee-W Lee-W merged commit dbcc173 into commitizen-tools:v3 Jan 5, 2023
@noirbizarre noirbizarre deleted the tests/fix-false-negatives branch January 5, 2023 12:58
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.

2 participants