-
Notifications
You must be signed in to change notification settings - Fork 137
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
add test using git #445
base: main
Are you sure you want to change the base?
add test using git #445
Conversation
git is isolated using the following environment, which are set globally for the duration of that the new pytest fixture "tmp_git" is used: GIT_CONFIG_GLOBAL GIT_CONFIG_NOSYSTEM HOME GIT_AUTHOR_EMAIL GIT_AUTHOR_NAME GIT_AUTHOR_DATE GIT_COMMITTER_EMAIL GIT_COMMITTER_NAME GIT_COMMITTER_DATE GIT_DIR and GIT_WORK_TREE could be set so that git can be called using any method, but instead a git() function is added that uses git's -C command-line option. These were taken from one of git's test scripts: https://github.com/git/git/blob/cefe983a320c03d7843ac78e73bd513a27806845/t/test-lib.sh#L454-L461 There are probably other ways git can be isolated. The repository is initialized with an empty commit, but this isn't strictly necessary, it just makes some of the possible tests require less setup. The new tmp_project fixture copies the sample module from ./test/samples/module1_toml to the project and commits the files. A test is added for pypa#345 as an example of how this can be used. A pytest marker is added so that tests with either "needgit" or "needsgit" in the name are skipped if python can't find an executable named "git". The tox configuration is changed and another pytest marker is added so that those tests can be run by themselves: tox -- -m needgit or skipped: tox -- -m "not needgit" Type hints were added to help with development, but aren't necessary to keep.
Thanks! This looks like a good start. I don't know exactly what's needed to isolate git either, so we may as well try it and fix things as they come up. 😄 The thing with the test names is indeed a bit more magic than I like. Let's just use an explicit I think having the fixtures automatically copy one working sample is a decent starting point for now. But I might try to separate the layer for calling git (including all those environment variables to make it consistent) from the layer that prepares a specific repository. We could always refactor that later when we want more flexibility, though. Lastly, it looks like the tests are failing on Windows (Appveyor CI). If needs be, we can skip it on Windows and only have the new tests on Linux for now, but if possible it would be good to figure it out. |
Thanks for being welcoming to contributions, and for giving very friendly feedback.
✔️ 7430aee
Currently, the The Is this separation of concerns sufficient? What did you have in mind?
It looks like the tests are working already! 😁 Summary of the bug: In the test this pr adds (starting from this line):
My personal preference with Python is to |
this is a focused fix as referenced in: pypa#445 (comment)
this is a focused fix for the problem referenced in: pypa#445 (comment)
this is a focused fix for the problem referenced in: pypa#445 (comment)
This adds a few pytest fixtures that set up a git repository using
git
.I used this stackoverflow answer to isolate git using these environment variable:
GIT_CONFIG_GLOBAL
GIT_CONFIG_NOSYSTEM
HOME
GIT_AUTHOR_EMAIL
GIT_AUTHOR_NAME
GIT_AUTHOR_DATE
GIT_COMMITTER_EMAIL
GIT_COMMITTER_NAME
GIT_COMMITTER_DATE
Instead of using
GIT_DIR
andGIT_WORK_TREE
, I added another fixture that forms a closure around git, and calls it's-C
command-line option, pointing to the temporary repository.I'm not familiar with testing git, so I'm not sure if these measures are sufficient.
The
tmp_git_repo
fixture initializes the temporary repository with an empty commit. This isn't strictly necessary, it just makes some of the possible tests require less setup.The
tmp_project
fixture copies the sample module from./tests/samples/module1_toml
to the repository and commits the files.A test is added for #345 as an example of how to use the new fixtures.
I wanted to be able to run
tox
andpytest
targeting or excluding only the tests that depend ongit
being installed:or skipped:
tox -- -m "not needgit"
I kept getting confused myself, so both
needgit
andneedsgit
work.Currently this is selected based on the test function name including
needgit
orneedsgit
, and I can understand if that's a bit too magical.The tests are skipped if
shutil.which("git")
returns nothing, though I did not test this.Possible changes
Would it make more sense to have
tmp_project
behave similarly to the existingcopy_sample
fixture?It could take as an argument the sample module and return a
contextmanager
-wrapped iterator that copies the named sample module files into the git repository and commits the changes: