dstandish commented on a change in pull request #14963:
URL: https://github.com/apache/airflow/pull/14963#discussion_r602420337



##########
File path: tests/operators/test_bash.py
##########
@@ -117,7 +117,31 @@ def test_default_retries(self):
 
         assert bash_operator.retries == 0
 
+    def test_command_not_found(self):
+        with pytest.raises(
+            AirflowException, match="Bash command failed\\. The command 
returned a non-zero exit code\\."
+        ):
+            BashOperator(task_id='abc', bash_command='set -e; 
something-that-isnt-on-path').execute({})
+
     def test_skip(self):
-        op = BashOperator(task_id='abc', bash_command='set -e; echo "hello 
world"; exit 127;')
-        with pytest.raises(AirflowSkipException):
-            op.execute({})
+        with pytest.raises(AirflowSkipException, match="Bash command returned 
exit code 99\\. Skipping\\."):
+            BashOperator(task_id='abc', bash_command='set -e; echo "hello 
world"; exit 99;').execute({})
+
+        with pytest.raises(AirflowSkipException, match="Bash command returned 
exit code 100\\. Skipping\\."):
+            BashOperator(
+                task_id='abc2', bash_command='set -e; echo "hello world"; exit 
100;', skip_exit_code=100
+            ).execute({})
+
+        with pytest.raises(
+            AirflowException, match="Bash command failed\\. The command 
returned a non-zero exit code\\."
+        ):
+            BashOperator(
+                task_id='abc3', bash_command='set -e; echo "hello world"; exit 
101;', skip_exit_code=100
+            ).execute({})
+
+        with pytest.raises(
+            AirflowException, match="Bash command failed\\. The command 
returned a non-zero exit code\\."
+        ):
+            BashOperator(
+                task_id='abc4', bash_command='set -e; echo "hello world"; exit 
99;', skip_exit_code=None
+            ).execute({})

Review comment:
       ```suggestion
       @parameterized.expand(
           [
               (None, 99, AirflowSkipException),
               ({'skip_exit_code': 100}, 100, AirflowSkipException),
               ({'skip_exit_code': 100}, 101, AirflowException),
               ({'skip_exit_code': None}, 99, AirflowException),
           ]
       )
       def test_skip(self, extra_kwargs, actual_exit_code, expected_exc):
           match = (
               f"Bash command returned exit code {actual_exit_code}\\. 
Skipping\\."
               if expected_exc == AirflowSkipException
               else "Bash command failed\\. The command returned a non-zero 
exit code\\."
           )
           kwargs = dict(task_id='abc', bash_command=f'set -e; echo "hello 
world"; exit {actual_exit_code};')
           if extra_kwargs:
               kwargs.update(**extra_kwargs)
           with pytest.raises(expected_exc, match=match):
               BashOperator(**kwargs).execute({})
   ```
   
   paramaterized here.... i think it makes it a lot easier to understand what's 
being tested
   
   i think we could probably skip the `match` part cus it does add quite a bit 
of noise and i think the main thing we're verifying here is what exception gets 
raised but i left it in

##########
File path: tests/operators/test_bash.py
##########
@@ -117,7 +117,31 @@ def test_default_retries(self):
 
         assert bash_operator.retries == 0
 
+    def test_command_not_found(self):
+        with pytest.raises(
+            AirflowException, match="Bash command failed\\. The command 
returned a non-zero exit code\\."
+        ):
+            BashOperator(task_id='abc', bash_command='set -e; 
something-that-isnt-on-path').execute({})
+
     def test_skip(self):
-        op = BashOperator(task_id='abc', bash_command='set -e; echo "hello 
world"; exit 127;')
-        with pytest.raises(AirflowSkipException):
-            op.execute({})
+        with pytest.raises(AirflowSkipException, match="Bash command returned 
exit code 99\\. Skipping\\."):
+            BashOperator(task_id='abc', bash_command='set -e; echo "hello 
world"; exit 99;').execute({})
+
+        with pytest.raises(AirflowSkipException, match="Bash command returned 
exit code 100\\. Skipping\\."):
+            BashOperator(
+                task_id='abc2', bash_command='set -e; echo "hello world"; exit 
100;', skip_exit_code=100
+            ).execute({})
+
+        with pytest.raises(
+            AirflowException, match="Bash command failed\\. The command 
returned a non-zero exit code\\."
+        ):
+            BashOperator(
+                task_id='abc3', bash_command='set -e; echo "hello world"; exit 
101;', skip_exit_code=100
+            ).execute({})
+
+        with pytest.raises(
+            AirflowException, match="Bash command failed\\. The command 
returned a non-zero exit code\\."
+        ):
+            BashOperator(
+                task_id='abc4', bash_command='set -e; echo "hello world"; exit 
99;', skip_exit_code=None
+            ).execute({})

Review comment:
       i couldn't make the suggestion across the deleted line so if you accept 
this you'll need to remove the extraneous `def test_skip(self):`




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to