-
Notifications
You must be signed in to change notification settings - Fork 14.6k
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
Simplify tests for CLI connections commands #21983
Simplify tests for CLI connections commands #21983
Conversation
def tearDown(self): | ||
clear_db_connections() | ||
def setup_method(self): | ||
clear_db_connections(add_default_connections_back=True) |
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 think we should do this after the test to clean up properly. Maybe a setup_class
and a teardown_method
so we ensure a clean slate both before and after each test.
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.
yeah i was thinking about that
maybe an autouse fixture in the module that clears after yield
they could all use same fixture except that only some of the classes require the example connectios
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.
like
@pytest.fixture(scope='class', autouse=True)
def clear_connections():
yield
clear_db_connections(add_default_connections_back=False)
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.
done
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.
Isn’t that essentially the same as
def teardown_method(self):
clear_db_connections(add_default_connections_back=False)
but more code?
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.
no because there are 4 (or more?) classes and this will apply to all of them... right?
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.
actually 6 :)
The tests (particularly with the export subcommand) were doing a fair bit of unnecessary mocking. In particular they mocked `builtins.open`. But there's no good reason that we can't actually write out the file and read the file in the assert (which is a much better way to test this). I suspect the reason that the author did this is because the file wasn't _closed_, so when you read the value from the exported file (if the process has not been exited) then the buffer may not be fully written to disk. I fix this by closing the file after writing the connections. As part of this change I also update to use current pytest techniques for parameterization and setup / teardown.
604aa35
to
d72c9fc
Compare
The PR is likely OK to be merged with just subset of tests for default Python and Database versions without running the full matrix of tests, because it does not modify the core of Airflow. If the committers decide that the full tests matrix is needed, they will add the label 'full tests needed'. Then you should rebase to the latest main or amend the last commit of the PR, and push it with --force-with-lease. |
The tests (particularly with the export subcommand) were doing a fair bit of unnecessary mocking. In particular they mocked
builtins.open
. But there's no good reason that we can't actually write out the file and read the file in the assert (which is a much better way to test this). There were also a number of assertions resplittext
which are not really relevant.I suspect the reason that the author did this is because the file wasn't closed, so when you read the value from the exported file (if the process has not been exited) then the buffer may not be fully written to disk. I fix this by closing the file after writing the connections.
As part of this change I also update to use current pytest techniques for parameterization and temp files.