summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorClaude Paroz <claude@2xlibre.net>2019-08-23 10:53:36 +0200
committerCarlton Gibson <carlton.gibson@noumenal.es>2019-08-23 10:53:36 +0200
commit9386586f31b8a0bccf59a1bff647cd829d4e79aa (patch)
treef28bf4c9b8b0a1431c1b6722f9d5bb613d78040f /tests
parent7bd963332017eace00be8caf7dc1b7b304da613a (diff)
Replaced subprocess commands by run() wherever possible.
Diffstat (limited to 'tests')
-rw-r--r--tests/admin_scripts/tests.py5
-rw-r--r--tests/dbshell/test_oracle.py9
-rw-r--r--tests/i18n/test_compilation.py4
-rwxr-xr-xtests/runtests.py10
-rw-r--r--tests/utils_tests/test_autoreload.py3
5 files changed, 17 insertions, 14 deletions
diff --git a/tests/admin_scripts/tests.py b/tests/admin_scripts/tests.py
index d6ea84da7a..1e4477ed34 100644
--- a/tests/admin_scripts/tests.py
+++ b/tests/admin_scripts/tests.py
@@ -118,12 +118,13 @@ class AdminScriptTestCase(SimpleTestCase):
test_environ['PYTHONPATH'] = os.pathsep.join(python_path)
test_environ['PYTHONWARNINGS'] = ''
- return subprocess.Popen(
+ p = subprocess.run(
[sys.executable, script] + args,
stdout=subprocess.PIPE, stderr=subprocess.PIPE,
cwd=self.test_dir,
env=test_environ, universal_newlines=True,
- ).communicate()
+ )
+ return p.stdout, p.stderr
def run_django_admin(self, args, settings_file=None):
script_dir = os.path.abspath(os.path.join(os.path.dirname(django.__file__), 'bin'))
diff --git a/tests/dbshell/test_oracle.py b/tests/dbshell/test_oracle.py
index d236a932ab..cfaf106d68 100644
--- a/tests/dbshell/test_oracle.py
+++ b/tests/dbshell/test_oracle.py
@@ -1,3 +1,4 @@
+from subprocess import CompletedProcess
from unittest import mock, skipUnless
from django.db import connection
@@ -9,13 +10,13 @@ from django.test import SimpleTestCase
class OracleDbshellTests(SimpleTestCase):
def _run_dbshell(self, rlwrap=False):
"""Run runshell command and capture its arguments."""
- def _mock_subprocess_call(*args):
- self.subprocess_args = tuple(*args)
- return 0
+ def _mock_subprocess_run(*args):
+ self.subprocess_args = list(*args)
+ return CompletedProcess(self.subprocess_args, 0)
client = DatabaseClient(connection)
self.subprocess_args = None
- with mock.patch('subprocess.call', new=_mock_subprocess_call):
+ with mock.patch('subprocess.run', new=_mock_subprocess_run):
with mock.patch('shutil.which', return_value='/usr/bin/rlwrap' if rlwrap else None):
client.runshell()
return self.subprocess_args
diff --git a/tests/i18n/test_compilation.py b/tests/i18n/test_compilation.py
index aa457f21f6..91e0714cec 100644
--- a/tests/i18n/test_compilation.py
+++ b/tests/i18n/test_compilation.py
@@ -4,7 +4,7 @@ import stat
import unittest
from io import StringIO
from pathlib import Path
-from subprocess import Popen
+from subprocess import run
from unittest import mock
from django.core.management import (
@@ -184,7 +184,7 @@ class CompilationErrorHandling(MessageCompilationTests):
# Make sure the output of msgfmt is unaffected by the current locale.
env = os.environ.copy()
env.update({'LANG': 'C'})
- with mock.patch('django.core.management.utils.Popen', lambda *args, **kwargs: Popen(*args, env=env, **kwargs)):
+ with mock.patch('django.core.management.utils.run', lambda *args, **kwargs: run(*args, env=env, **kwargs)):
cmd = MakeMessagesCommand()
if cmd.gettext_version < (0, 18, 3):
self.skipTest("python-brace-format is a recent gettext addition.")
diff --git a/tests/runtests.py b/tests/runtests.py
index 840c06321d..be1760e693 100755
--- a/tests/runtests.py
+++ b/tests/runtests.py
@@ -355,22 +355,22 @@ def bisect_tests(bisection_label, options, test_labels, parallel, start_at, star
test_labels_b = test_labels[midpoint:] + [bisection_label]
print('***** Pass %da: Running the first half of the test suite' % iteration)
print('***** Test labels: %s' % ' '.join(test_labels_a))
- failures_a = subprocess.call(subprocess_args + test_labels_a)
+ failures_a = subprocess.run(subprocess_args + test_labels_a)
print('***** Pass %db: Running the second half of the test suite' % iteration)
print('***** Test labels: %s' % ' '.join(test_labels_b))
print('')
- failures_b = subprocess.call(subprocess_args + test_labels_b)
+ failures_b = subprocess.run(subprocess_args + test_labels_b)
- if failures_a and not failures_b:
+ if failures_a.returncode and not failures_b.returncode:
print("***** Problem found in first half. Bisecting again...")
iteration += 1
test_labels = test_labels_a[:-1]
- elif failures_b and not failures_a:
+ elif failures_b.returncode and not failures_a.returncode:
print("***** Problem found in second half. Bisecting again...")
iteration += 1
test_labels = test_labels_b[:-1]
- elif failures_a and failures_b:
+ elif failures_a.returncode and failures_b.returncode:
print("***** Multiple sources of failure found")
break
else:
diff --git a/tests/utils_tests/test_autoreload.py b/tests/utils_tests/test_autoreload.py
index b673c5e1c0..2216d003ee 100644
--- a/tests/utils_tests/test_autoreload.py
+++ b/tests/utils_tests/test_autoreload.py
@@ -11,6 +11,7 @@ import weakref
import zipfile
from importlib import import_module
from pathlib import Path
+from subprocess import CompletedProcess
from unittest import mock, skip, skipIf
from django.apps.registry import Apps
@@ -345,7 +346,7 @@ class RestartWithReloaderTests(SimpleTestCase):
executable = '/usr/bin/python'
def patch_autoreload(self, argv):
- patch_call = mock.patch('django.utils.autoreload.subprocess.call', return_value=0)
+ patch_call = mock.patch('django.utils.autoreload.subprocess.run', return_value=CompletedProcess(argv, 0))
patches = [
mock.patch('django.utils.autoreload.sys.argv', argv),
mock.patch('django.utils.autoreload.sys.executable', self.executable),