Skip to content
Snippets Groups Projects
Unverified Commit 6fa25509 authored by Feanil Patel's avatar Feanil Patel Committed by GitHub
Browse files

Merge pull request #21592 from edx/feanil/fix_jenkins_tests

Feanil/fix jenkins tests in python 3
parents 52be01a5 d01df30a
No related branches found
No related tags found
No related merge requests found
......@@ -308,3 +308,5 @@ derive_settings(__name__)
SYSTEM_WIDE_ROLE_CLASSES = os.environ.get("SYSTEM_WIDE_ROLE_CLASSES", [])
DEFAULT_MOBILE_AVAILABLE = True
PROCTORING_SETTINGS = {}
......@@ -594,3 +594,5 @@ ACCOUNT_MICROFRONTEND_URL = "http://account-mfe/"
########################## limiting dashboard courses ######################
DASHBOARD_COURSE_LIMIT = 250
PROCTORING_SETTINGS = {}
......@@ -115,3 +115,5 @@ USE_TZ = True
RETIREMENT_SERVICE_WORKER_USERNAME = 'RETIREMENT_SERVICE_USER'
RETIRED_USERNAME_PREFIX = 'retired__user_'
PROCTORING_SETTINGS = {}
# pylint: disable=unicode-format-string
"""
Tests for the pytest paver commands themselves.
Run just this test with: paver test_lib -t pavelib/paver_tests/test_paver_pytest_cmds.py
"""
from __future__ import absolute_import
import os
import unittest
import ddt
from pavelib.utils.envs import Env
from pavelib.utils.test.suites import LibTestSuite, SystemTestSuite
XDIST_TESTING_IP_ADDRESS_LIST = '0.0.0.1,0.0.0.2,0.0.0.3'
@ddt.ddt
class TestPaverPytestCmd(unittest.TestCase):
"""
Test Paver pytest commands
"""
def _expected_command(self, root, test_id, pytestSubclass, run_under_coverage=True,
processes=0, xdist_ip_addresses=None):
"""
Returns the command that is expected to be run for the given test spec
and store.
"""
report_dir = Env.REPORT_DIR / root
shard = os.environ.get('SHARD')
if shard:
report_dir = report_dir / 'shard_' + shard
expected_statement = [
"python",
"-Wd",
"-m",
"pytest"
]
if pytestSubclass == "SystemTestSuite":
expected_statement.append("--ds={}".format('{}.envs.{}'.format(root, Env.TEST_SETTINGS)))
expected_statement.append("--junitxml={}".format(report_dir / "nosetests.xml"))
if xdist_ip_addresses:
expected_statement.append('--dist=loadscope')
for ip in xdist_ip_addresses.split(','):
if processes <= 0:
processes = 1
if pytestSubclass == "SystemTestSuite":
django_env_var_cmd = u"export DJANGO_SETTINGS_MODULE={}.envs.test".format(root)
elif pytestSubclass == "LibTestSuite":
if 'pavelib/paver_tests' in test_id:
django_env_var_cmd = u"export DJANGO_SETTINGS_MODULE={}.envs.test".format(root)
else:
django_env_var_cmd = "export DJANGO_SETTINGS_MODULE='openedx.tests.settings'"
env_var_cmd = "{} DISABLE_COURSEENROLLMENT_HISTORY=1".format(django_env_var_cmd)
xdist_string = u'--tx {}*ssh="jenkins@{} -o StrictHostKeyChecking=no"' \
'//python="source edx-venv/bin/activate; {}; python"' \
'//chdir="edx-platform"' \
.format(processes, ip, env_var_cmd)
expected_statement.append(xdist_string)
for rsync_dir in Env.rsync_dirs():
expected_statement.append(u'--rsyncdir {}'.format(rsync_dir))
else:
if processes == -1:
expected_statement.append('-n auto')
expected_statement.append('--dist=loadscope')
elif processes != 0:
expected_statement.append(u'-n {}'.format(processes))
expected_statement.append('--dist=loadscope')
expected_statement.extend([
"-p no:randomly",
test_id
])
if run_under_coverage:
expected_statement.append('--cov')
expected_statement.append('--cov-report=')
return expected_statement
@ddt.data('lms', 'cms')
def test_SystemTestSuite_suites(self, system):
test_id = 'tests'
suite = SystemTestSuite(system, test_id=test_id)
assert suite.cmd == self._expected_command(system, test_id, "SystemTestSuite")
@ddt.data('lms', 'cms')
def test_SystemTestSuite_auto_processes(self, system):
test_id = 'tests'
suite = SystemTestSuite(system, test_id=test_id, processes=-1)
assert suite.cmd == self._expected_command(system, test_id, "SystemTestSuite", processes=-1)
@ddt.data('lms', 'cms')
def test_SystemTestSuite_multi_processes(self, system):
test_id = 'tests'
suite = SystemTestSuite(system, test_id=test_id, processes=3)
assert suite.cmd == self._expected_command(system, test_id, "SystemTestSuite", processes=3)
@ddt.data('lms', 'cms')
def test_SystemTestSuite_with_xdist(self, system):
test_id = 'tests'
suite = SystemTestSuite(system, test_id=test_id, xdist_ip_addresses=XDIST_TESTING_IP_ADDRESS_LIST)
assert suite.cmd == self._expected_command(system, test_id, "SystemTestSuite",
xdist_ip_addresses=XDIST_TESTING_IP_ADDRESS_LIST)
@ddt.data('lms', 'cms')
def test_SystemTestSuite_with_xdist_multi_processes(self, system):
test_id = 'tests'
suite = SystemTestSuite(system, test_id=test_id, processes=2, xdist_ip_addresses=XDIST_TESTING_IP_ADDRESS_LIST)
assert suite.cmd == self._expected_command(system, test_id, "SystemTestSuite", processes=2,
xdist_ip_addresses=XDIST_TESTING_IP_ADDRESS_LIST)
@ddt.data('lms', 'cms')
def test_SystemTestSuite_with_xdist_negative_processes(self, system):
test_id = 'tests'
suite = SystemTestSuite(system, test_id=test_id, processes=-1, xdist_ip_addresses=XDIST_TESTING_IP_ADDRESS_LIST)
assert suite.cmd == self._expected_command(system, test_id, "SystemTestSuite", processes=-1,
xdist_ip_addresses=XDIST_TESTING_IP_ADDRESS_LIST)
@ddt.data('common/lib/xmodule', 'pavelib/paver_tests')
def test_LibTestSuite_suites(self, system):
test_id = 'tests'
suite = LibTestSuite(system, test_id=test_id)
assert suite.cmd == self._expected_command(system, test_id, "LibTestSuite")
@ddt.data('common/lib/xmodule', 'pavelib/paver_tests')
def test_LibTestSuite_auto_processes(self, system):
test_id = 'tests'
suite = LibTestSuite(system, test_id=test_id, processes=-1)
assert suite.cmd == self._expected_command(system, test_id, "LibTestSuite", processes=-1)
@ddt.data('common/lib/xmodule', 'pavelib/paver_tests')
def test_LibTestSuite_multi_processes(self, system):
test_id = 'tests'
suite = LibTestSuite(system, test_id=test_id, processes=3)
assert suite.cmd == self._expected_command(system, test_id, "LibTestSuite", processes=3)
@ddt.data('common/lib/xmodule', 'pavelib/paver_tests')
def test_LibTestSuite_with_xdist(self, system):
test_id = 'tests'
suite = LibTestSuite(system, test_id=test_id, xdist_ip_addresses=XDIST_TESTING_IP_ADDRESS_LIST)
assert suite.cmd == self._expected_command(system, test_id, "LibTestSuite",
xdist_ip_addresses=XDIST_TESTING_IP_ADDRESS_LIST)
@ddt.data('common/lib/xmodule', 'pavelib/paver_tests')
def test_LibTestSuite_with_xdist_multi_processes(self, system):
test_id = 'tests'
suite = LibTestSuite(system, test_id=test_id, processes=2, xdist_ip_addresses=XDIST_TESTING_IP_ADDRESS_LIST)
assert suite.cmd == self._expected_command(system, test_id, "LibTestSuite", processes=2,
xdist_ip_addresses=XDIST_TESTING_IP_ADDRESS_LIST)
@ddt.data('common/lib/xmodule', 'pavelib/paver_tests')
def test_LibTestSuite_with_xdist_negative_processes(self, system):
test_id = 'tests'
suite = LibTestSuite(system, test_id=test_id, processes=-1, xdist_ip_addresses=XDIST_TESTING_IP_ADDRESS_LIST)
assert suite.cmd == self._expected_command(system, test_id, "LibTestSuite", processes=-1,
xdist_ip_addresses=XDIST_TESTING_IP_ADDRESS_LIST)
......@@ -180,7 +180,7 @@ class SystemTestSuite(PytestSuite):
xdist_remote_processes = self.processes
for ip in self.xdist_ip_addresses.split(','):
# Propogate necessary env vars to xdist containers
env_var_cmd = u'export DJANGO_SETTINGS_MODULE={} DISABLE_COURSEENROLLMENT_HISTORY={}'\
env_var_cmd = u'export DJANGO_SETTINGS_MODULE={} DISABLE_COURSEENROLLMENT_HISTORY={} PYTHONHASHSEED=0'\
.format('{}.envs.{}'.format(self.root, self.settings),
self.disable_courseenrollment_history)
xdist_string = u'--tx {}*ssh="jenkins@{} -o StrictHostKeyChecking=no"' \
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment