-
Notifications
You must be signed in to change notification settings - Fork 0
Add hook to check test file names #252
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
Draft
jl-wynen
wants to merge
1
commit into
main
Choose a base branch
from
check-test-file-names
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| from pathlib import Path | ||
| import sys | ||
|
|
||
| ALLOWED_NAMES = ("conftest.py",) | ||
|
|
||
|
|
||
| def main(): | ||
| errors = False | ||
| paths = map(Path, sys.argv[1:]) | ||
| for path in paths: | ||
| if path.name in ALLOWED_NAMES: | ||
| continue | ||
| if not path.stem.endswith("_test"): | ||
| sys.stderr.write(f"Bad test file name: {path}\n") | ||
| errors = True | ||
|
|
||
| sys.exit(int(errors)) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| main() |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did I understand correctly that it will flag any file that does not end with
_test?Sometimes we may have some code in a module that isn't a test but contains common code for setting up tests? And I think these are not always in the
conftest.py?That's probably the case for the mcstas example thing. Is it always possible to move to a conftest file, or are there cases where we cannot?
Also, do we ever have non-python files in the
test/folder, which could end in something else? Like some data files for testing?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess we can always use the conftest file ...
And then we can accept all non-python files under the tests folder.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file is imported by only one other file. So as long as it stays that way, we can move the contents to that importing file.
The regex will only look for .py files. So anything else won't be checked and therefore will be accepted.
Correct. I think in principle, we can always move common code into fixtures. But that does not always make sense.
Looking through our ess* packages, I found one case in loki:
common.py. This defines a single function to create a workflow which could be provided as a fixture. We do that in other packages.And esslivedata has a number of modules in its tests. But they seem to define fixtures. So they could be moved into a conftest.py file. But that file would be fairly large.