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
Remove unittest #3245
Remove unittest #3245
Conversation
Sorry about all the pings through CODEOWNERS, can't deselect people in the "new PR" thingy, apparently |
This is basically..
import re
import sys
path = sys.argv[1]
lines = []
with open(path, "rt", encoding="UTF-8") as fh:
for line in fh:
# remove unittest imports
if line.strip() == 'import unittest':
continue
if line.strip() == 'from unittest import mock':
continue
# remove inheritance from unittest on test classes
if re.match(r'class [^(]+\(unittest\.TestCase\):', line):
line = re.sub(r'\(unittest\.TestCase\):', '():', line, count=1)
# remove "suite" setup
if re.match(r'def suite\(', line):
while not line.startswith(' return '):
line = fh.readline()
continue
# remove hook for CLI execution of tests by calling file
if re.match(r"if __name__ == (['\"])__main__\1:", line):
line = fh.readline()
while line.startswith(" "):
line = fh.readline()
continue
# replace skip decorator
if re.search(r'@unittest.skipIf\(', line):
line = re.sub(r'@unittest.skipIf\(([^,]*), (.*)\)', r'@pytest.mark.skipif(\1, reason=\2)', line)
line = re.sub(r'@unittest.skipIf\(([^,]*)\)', r'@pytest.mark.skipif(\1)', line)
lines.append(line)
# remove empty lines at end (due to some content line removals around end of
# file (suite / __main__)
while not lines[-1].strip():
lines.pop()
for line in lines:
if "unittest" in lines:
print(f'found "unittest" in path "{path}"')
break
with open(path, "wt", encoding="UTF-8") as fh:
fh.writelines(lines) |
Oh.. wasn't aware that the linter isn't run with |
Nice! I think you do not want to remove the mock line with
|
Yea I realized that one.. 🤣 just added those few ones back manually |
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 skimmed through the changes. Looks OK to me!
Not yet ready.. more transistioning to do 😬 |
Holy crap, wouldn't have touched this had I known how much of a rabbit hole this was |
|
Ah right, I thought they were run once, that mustve been some other unittest construct I somehow remembered |
8bbae00
to
81a9be0
Compare
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.
Gave it a reasonable skim and noted some things that could be improved. Probably missed several cases that are similar, and these could conceivably be in a followup PR instead.
139002e
to
7ac6935
Compare
@trichter is the |
@QuLogic found many more occurences of message checking in newly refactored |
That is the expected behavior. The test_network label adds runs with the |
Ah gotcha, I thought it just ran all tests on existing runners |
- unify path lookups of test files with fixtures - use pathlib more for path building - some other minor changes, get rid of unittest style test case setups etc.
- use match in pytest.raises everywhere - set literals
7ac6935
to
97fe3f5
Compare
They can be extracted from the json so should not be to hard to do. You mean like filter for network test runs? Then it would mean changing the database structure probably. |
Yep, I looked them up in the JSON from time to time. A filter would be great. And/or a new column, this could simply have a flags header with values |
The PR looks good to me! |
Did just merge maintenance branch into master and pushed it, so both will be easily merge-able going forward |
What does this PR do?
Get rid of unittest from the whole test code base and replace with pytest.
(Except for
mock
module which comes inunittest
)Generally this would belong into
master
but if we do it there we end up with a massive diff between maintenance and master branch and will end up in merge hell most likely a lot of times when merging things back intomaster
frommaintenance
.Why was it initiated? Any relevant Issues?
Make testing code base more consistent.
PR Checklist
master
for new features,maintenance_...
for bug fixesno_ci
label can be added to skip CI buildsJust add the
build_docs
tag to this PR.Docs will be served at docs.obspy.org/pr/{branch_name} (do not use master branch).
Please post a link to the relevant piece of documentation.
clients.fdsn
) should be tested for the PR,just add the
test_network
tag to this PR.CHANGELOG.txt
.CONTRIBUTORS.txt
.from all the CI builds look correct. Add the "upload_plots" tag so that plotting
outputs are attached as artifacts.
CODEOWNERS
with your github handleready for review
tag when you are ready for the PR to be reviewed.