Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions tests/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
from airflow.utils.dates import days_ago, infer_time_unit, round_time, scale_time_units
from airflow.utils.state import State
from airflow.utils.timezone import datetime
from airflow.version import version
from tests.test_utils.config import conf_vars

DEV_NULL = '/dev/null'
Expand Down Expand Up @@ -1795,6 +1796,12 @@ def test_variables(self):
os.remove('variables2.json')
os.remove('variables3.json')

def test_cli_version(self):
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'm afraid this test is in the wrong place. tests/cli/test_cli.py is a better file.

I am also afraid of sys.stdout mocking. Python has a special mechanism for this. 
https://github.com/sekikn/incubator-airflow/blob/9ff0c4f79a009618215a2af60418f664168456f4/tests/cli/test_cli.py#L344-L352

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the comment @mik-laj!

I'm afraid this test is in the wrong place. tests/cli/test_cli.py is a better file.

The reason that I added the new test to test/core.py was it has many cli-related tests in its TestCli class. I have no objection to move the new test into tests/cli/test_cli.py, but is there any criteria to put a new cli-related test into it (or should we basically use tests/cli/test_cli.py in the future)?

I am also afraid of sys.stdout mocking. Python has a special mechanism for this.

I didn't use contextlib.redirect_stdout because of concern for the compatibility with Python2, but I've just noticed we're going to drop it on the master branch. I'll address it on another PR, thanks :)

with mock.patch('sys.stdout', new_callable=io.StringIO) as mock_stdout:
cli.version(self.parser.parse_args(['version']))
stdout = mock_stdout.getvalue()
self.assertIn(version, stdout)

def _wait_pidfile(self, pidfile):
while True:
try:
Expand Down