You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by ka...@apache.org on 2021/11/03 00:21:33 UTC

[airflow] branch main updated: Tests: Refactor ``LoggingCommandExecutor`` to use subprocess devnull (#19354)

This is an automated email from the ASF dual-hosted git repository.

kaxilnaik pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git


The following commit(s) were added to refs/heads/main by this push:
     new e57c742  Tests: Refactor ``LoggingCommandExecutor`` to use subprocess devnull (#19354)
e57c742 is described below

commit e57c74263884ad5827a5bb9973eb698f0c269cc8
Author: Shakaib Khan <sh...@gmail.com>
AuthorDate: Tue Nov 2 20:20:57 2021 -0400

    Tests: Refactor ``LoggingCommandExecutor`` to use subprocess devnull (#19354)
    
    Co-authored-by: Shakaib Khan <sh...@Shakaibs-MacBook-Pro.local>
---
 tests/test_utils/logging_command_executor.py | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/tests/test_utils/logging_command_executor.py b/tests/test_utils/logging_command_executor.py
index 7d8749d..f9e8e8c 100644
--- a/tests/test_utils/logging_command_executor.py
+++ b/tests/test_utils/logging_command_executor.py
@@ -15,7 +15,6 @@
 # KIND, either express or implied.  See the License for the
 # specific language governing permissions and limitations
 # under the License.
-import os
 import shlex
 import subprocess
 
@@ -31,8 +30,9 @@ class LoggingCommandExecutor(LoggingMixin):
     def execute_cmd(self, cmd, silent=False, cwd=None, env=None):
         if silent:
             self.log.info("Executing in silent mode: '%s'", " ".join(shlex.quote(c) for c in cmd))
-            with open(os.devnull, 'w') as dev_null:
-                return subprocess.call(args=cmd, stdout=dev_null, stderr=subprocess.STDOUT, env=env, cwd=cwd)
+            return subprocess.call(
+                args=cmd, stdout=subprocess.DEVNULL, stderr=subprocess.STDOUT, env=env, cwd=cwd
+            )
         else:
             self.log.info("Executing: '%s'", " ".join(shlex.quote(c) for c in cmd))
             with subprocess.Popen(
@@ -78,8 +78,9 @@ class CommandExecutor(LoggingCommandExecutor):
     def execute_cmd(self, cmd, silent=False, cwd=None, env=None):
         if silent:
             self.log.info("Executing in silent mode: '%s'", " ".join(shlex.quote(c) for c in cmd))
-            with open(os.devnull, 'w') as dev_null:
-                return subprocess.call(args=cmd, stdout=dev_null, stderr=subprocess.STDOUT, env=env, cwd=cwd)
+            return subprocess.call(
+                args=cmd, stdout=subprocess.DEVNULL, stderr=subprocess.STDOUT, env=env, cwd=cwd
+            )
         else:
             self.log.info("Executing: '%s'", " ".join(shlex.quote(c) for c in cmd))
             with subprocess.Popen(