Skip to content

Commit

Permalink
Merge pull request #121 from rebkwok/parallelise-tests
Browse files Browse the repository at this point in the history
Parallelise tests
  • Loading branch information
rebkwok committed Jan 15, 2023
2 parents 0d4d268 + b5a19ee commit 1726e97
Show file tree
Hide file tree
Showing 14 changed files with 54 additions and 31 deletions.
1 change: 0 additions & 1 deletion .coverage

This file was deleted.

15 changes: 3 additions & 12 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,22 +51,13 @@ jobs:
- name: Run tests
env:
SECRET_KEY: 'dummy_secret'
EMAIL_HOST_PASSWORD: 'dummy_password'
DATABASE_URL: postgres://postgres:postgres@localhost/ci_test
DEFAULT_PAYPAL_EMAIL: dummy-email@hotmail.com
PAYPAL_TEST: True
LOG_FOLDER: log_folder
TRAVIS: True
HEROKU: False
SEND_ALL_STUDIO_EMAILS: True
SIMPLECRYPT_PASSWORD: secret
VAT_NUMBER: 123
run: |
source ${{ github.workspace }}/venv/bin/activate
pytest --cov-config=.coveragerc --cov=.
pytest --cov-config=.coveragerc --cov=. -k 'serial'
pytest --cov-config=.coveragerc --cov=. --cov-append -n auto -k 'not serial'
- name: Coveralls
uses: AndreMiras/coveralls-python-action@develop
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
github-token: ${{ secrets.GITHUB_TOKEN }}
1 change: 1 addition & 0 deletions accounts/tests/test_forms.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from datetime import date, datetime
from datetime import timezone as dt_timezone
from model_bakery import baker
import pytest

from django.test import TestCase
from django.contrib.auth.models import User
Expand Down
2 changes: 2 additions & 0 deletions accounts/tests/test_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from pathlib import Path

from model_bakery import baker
import pytest

from django.conf import settings
from django.core import management, mail
Expand Down Expand Up @@ -217,6 +218,7 @@ def test_export_disclaimers_with_filename_argument(self):
bu_file.unlink()


@pytest.mark.serial
@override_settings(LOG_FOLDER=os.path.dirname(__file__))
class ExportEncryptedDisclaimersTests(TestCase):

Expand Down
3 changes: 2 additions & 1 deletion accounts/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from requests.auth import HTTPBasicAuth
from requests.exceptions import HTTPError
from unittest.mock import call, Mock
import pytest

from django.conf import settings
from django.contrib.auth.models import User, Group
Expand Down Expand Up @@ -782,4 +783,4 @@ def test_create_new_agreement_with_unsubscribe(self):
self.assertFalse(self.user.subscribed())
assert_mailchimp_post_data(
self.mock_request, self.user, 'unsubscribed'
)
)
14 changes: 7 additions & 7 deletions booking/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1510,30 +1510,30 @@ class BlockTypeTests(TestCase):

def test_cannot_create_multiple_free_class_block_types(self):
ev_type = baker.make_recipe('booking.event_type_PC')
baker.make(BlockType, event_type=ev_type, identifier='free class')
baker.make(BlockType, event_type=ev_type, identifier='free class', duration=1)
self.assertEqual(BlockType.objects.count(), 1)

with self.assertRaises(BlockTypeError):
baker.make(BlockType, event_type=ev_type, identifier='free class')
baker.make(BlockType, event_type=ev_type, identifier='free class', duration=1)
self.assertEqual(BlockType.objects.count(), 1)

def test_cannot_create_multiple_transfer_block_types(self):
ev_type = baker.make_recipe('booking.event_type_PC')
baker.make(BlockType, event_type=ev_type, identifier='transferred')
baker.make(BlockType, event_type=ev_type, identifier='transferred', duration=1)
self.assertEqual(BlockType.objects.count(), 1)

with self.assertRaises(BlockTypeError):
baker.make(BlockType, event_type=ev_type, identifier='transferred')
baker.make(BlockType, event_type=ev_type, identifier='transferred', duration=1)
self.assertEqual(BlockType.objects.count(), 1)

def test_cann_create_transfer_block_types_for_different_events(self):
pc_ev_type = baker.make_recipe('booking.event_type_PC')
pp_ev_type = baker.make_recipe('booking.event_type_PP')

baker.make(BlockType, event_type=pc_ev_type, identifier='transferred')
baker.make(BlockType, event_type=pc_ev_type, identifier='transferred', duration=1)
self.assertEqual(BlockType.objects.count(), 1)

baker.make(BlockType, event_type=pp_ev_type, identifier='transferred')
baker.make(BlockType, event_type=pp_ev_type, identifier='transferred', duration=1)
self.assertEqual(BlockType.objects.count(), 2)


Expand Down Expand Up @@ -1645,4 +1645,4 @@ def test_event_type_or_block_type_required(self):
def test_gift_voucher_cost(self):
block_type = baker.make_recipe("booking.blocktype5", cost=40)
gift_voucher_type = GiftVoucherType.objects.create(block_type=block_type)
assert gift_voucher_type.cost == 40
assert gift_voucher_type.cost == 40
14 changes: 7 additions & 7 deletions pipsevents/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,20 @@
PAYPAL_TEST=(bool, False),
USE_MAILCATCHER=(bool, False),
CONSOLE_EMAIL=(bool, False),
HEROKU=(bool, False),
SEND_ALL_STUDIO_EMAILS=(bool, False),
AUTO_BOOK_EMAILS=(list, []),
REGULAR_STUDENT_WHITELIST_IDS=(list, []),
WACTHLIST=(list, []),
LOCAL=(bool, False),
SHOW_VAT=(bool, True),
TESTING=(bool, False)
)

environ.Env.read_env(root('pipsevents/.env')) # reading .env file

TESTING = any([test_str in arg for arg in sys.argv for test_str in ["test", "pytest"]])
TESTING = env("TESTING")
if not TESTING: # pragma: no cover
TESTING = any([test_str in arg for arg in sys.argv for test_str in ["test", "pytest"]])

BASE_DIR = root()
#
Expand Down Expand Up @@ -231,7 +233,7 @@
SEND_ALL_STUDIO_EMAILS = env('SEND_ALL_STUDIO_EMAILS')

# #####LOGGING######
if not env('HEROKU') and not TESTING: # pragma: no cover
if not TESTING: # pragma: no cover
LOG_FOLDER = env('LOG_FOLDER')

LOGGING = {
Expand Down Expand Up @@ -309,8 +311,6 @@

ADMINS = [("Becky Smith", SUPPORT_EMAIL)]

# ####HEROKU#######

# Honor the 'X-Forwarded-Proto' header for request.is_secure()
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')

Expand Down Expand Up @@ -372,8 +372,8 @@
PAYPAL_TEST = env('PAYPAL_TEST')


# TESTING and HEROKU logging
if env('HEROKU') or TESTING: # pragma: no cover
# TESTING logging
if TESTING: # pragma: no cover
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
Expand Down
17 changes: 16 additions & 1 deletion pytest.ini
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,19 @@ python_files = test*.py
DJANGO_SETTINGS_MODULE = pipsevents.settings

filterwarnings =
ignore::django.utils.deprecation.RemovedInDjango50Warning:model_bakery
ignore::django.utils.deprecation.RemovedInDjango50Warning:model_bakery

markers =
serial

env =
TESTING=1
SECRET_KEY=dummy_secret
EMAIL_HOST_PASSWORD=dummy_password
DEFAULT_PAYPAL_EMAIL=dummy-email@hotmail.com
PAYPAL_TEST=True
LOG_FOLDER=log_folder
HEROKU=False
SEND_ALL_STUDIO_EMAILS=True
SIMPLECRYPT_PASSWORD=secret
VAT_NUMBER=123
4 changes: 3 additions & 1 deletion requirements.in
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,6 @@ beautifulsoup4
git+https://github.com/KyleKing/simple-crypt.git
pytest
pytest-django
pytest-cov
pytest-cov
pytest-env
pytest-xdist
8 changes: 8 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ djangorestframework==3.14.0
# via -r requirements.in
docopt==0.6.2
# via coveralls
execnet==1.9.0
# via pytest-xdist
gunicorn==20.1.0
# via -r requirements.in
idna==3.4
Expand Down Expand Up @@ -117,10 +119,16 @@ pytest==7.1.3
# -r requirements.in
# pytest-cov
# pytest-django
# pytest-env
# pytest-xdist
pytest-cov==3.0.0
# via -r requirements.in
pytest-django==4.5.2
# via -r requirements.in
pytest-env==0.8.1
# via -r requirements.in
pytest-xdist==3.1.0
# via -r requirements.in
python-dateutil==2.8.2
# via -r requirements.in
python3-openid==3.2.0
Expand Down
2 changes: 2 additions & 0 deletions studioadmin/tests/test_views/test_mailing_list_views.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from model_bakery import baker

import pytest

from django.contrib.auth.models import Group, User
from django.urls import reverse
from django.test import TestCase
Expand Down
1 change: 1 addition & 0 deletions studioadmin/tests/test_views/test_misc_views.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from unittest.mock import patch
from model_bakery import baker
import pytest

from django.urls import reverse
from django.core import mail
Expand Down
2 changes: 1 addition & 1 deletion studioadmin/tests/test_views/test_register_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ def test_full_event_shows_no_new_booking_button(self):
self.assertFalse(resp.context_data['can_add_more'])

def test_with_available_block_type_for_event(self):
baker.make(BlockType, event_type=self.pc.event_type)
baker.make(BlockType, event_type=self.pc.event_type, duration=1)
resp = self.client.get(self.pc_url)
self.assertTrue(resp.context_data['available_block_type'])

Expand Down
1 change: 1 addition & 0 deletions studioadmin/tests/test_views/test_user_views.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from model_bakery import baker
import pytest

from django.urls import reverse
from django.db.models import Q
Expand Down

0 comments on commit 1726e97

Please sign in to comment.