Skip to content

Commit cbec8dd

Browse files
fmooragjohnson
authored andcommitted
make tests parallelizable using pytest-xdist (#2899)
Be ware that running tests in parallel may cause tests to flake. This commit does not make parallel test the default it only makes it possible.
1 parent e92c3f5 commit cbec8dd

File tree

6 files changed

+16
-4
lines changed

6 files changed

+16
-4
lines changed

readthedocs/rtd_tests/base.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import os
33
import shutil
44
import logging
5+
import tempfile
56
from collections import OrderedDict
67

78
from mock import patch
@@ -18,7 +19,7 @@ class RTDTestCase(TestCase):
1819
def setUp(self):
1920
self.original_DOCROOT = settings.DOCROOT
2021
self.cwd = os.path.dirname(__file__)
21-
self.build_dir = os.path.join(self.cwd, 'builds')
22+
self.build_dir = tempfile.mkdtemp()
2223
log.info("build dir: %s", self.build_dir)
2324
if not os.path.exists(self.build_dir):
2425
os.makedirs(self.build_dir)

readthedocs/rtd_tests/tests/test_middleware.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from django_dynamic_fixture import get, new
88

99
from corsheaders.middleware import CorsMiddleware
10+
from mock import patch
1011

1112
from readthedocs.core.middleware import SubdomainMiddleware
1213
from readthedocs.projects.models import Project, Domain
@@ -95,10 +96,12 @@ def test_request_header_uppercase(self):
9596
self.assertEqual(request.slug, 'pip')
9697

9798
@override_settings(USE_SUBDOMAIN=True)
99+
# no need to do a real dns query so patch cname_to_slug
100+
@patch('readthedocs.core.middleware.cname_to_slug', new=lambda x: 'doesnt')
98101
def test_use_subdomain_on(self):
99102
request = self.factory.get(self.url, HTTP_HOST='doesnt.really.matter')
100103
ret_val = self.middleware.process_request(request)
101-
self.assertEqual(ret_val, None)
104+
self.assertIsNone(ret_val, None)
102105

103106

104107
class TestCORSMiddleware(TestCase):

readthedocs/settings/test.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ class CommunityTestSettings(CommunityDevSettings):
1313
PRODUCTION_DOMAIN = 'readthedocs.org'
1414
GROK_API_HOST = 'http://localhost:8888'
1515

16+
DEBUG = False
17+
TEMPLATE_DEBUG = False
18+
1619

1720
CommunityTestSettings.load_settings(__name__)
1821

requirements/pip.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ django-extensions==1.7.4
1818
djangorestframework==3.5.4
1919
django-vanilla-views==1.0.4
2020
jsonfield==1.0.3
21-
pytest-django==2.8.0
2221

2322
requests==2.3.0
2423
slumber==0.6.0

requirements/testing.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
-r pip.txt
2+
3+
pytest-django==2.8.0
4+
pytest-xdist==1.16.0
5+
apipkg==1.4
6+
execnet==1.4.1

tox.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ setenv =
88
DJANGO_SETTINGS_MODULE=settings.test
99
LANG=C
1010
DJANGO_SETTINGS_SKIP_LOCAL=True
11-
deps = -r{toxinidir}/requirements/pip.txt
11+
deps = -r{toxinidir}/requirements/testing.txt
1212
changedir = {toxinidir}/readthedocs
1313
commands =
1414
py.test {posargs}

0 commit comments

Comments
 (0)