mirror of
https://github.com/pretix/pretix.git
synced 2026-08-13 11:17:01 +00:00
Speed up the test suite
This commit is contained in:
@@ -83,15 +83,14 @@ Code checks and unit tests
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
Before you check in your code into git, always run the static checkers and unit tests::
|
||||
|
||||
flake8 .
|
||||
flake8 --ignore=E123,E128,F403,F401,N802,W503 .
|
||||
isort -c -rc .
|
||||
python manage.py check
|
||||
py.test
|
||||
|
||||
The ``flake8`` command by default is a bit stricter than what we really enforce, but we do enforce that all commits
|
||||
produce no output from::
|
||||
|
||||
flake8 --ignore=E123,E128,F403,F401,N802,W503 .
|
||||
If you have multiple CPU cores and want to speed up the test suite, you can install the python
|
||||
package ``pytest-xdist`` using ``pip install pytest-xdist`` and then run ``py.test -n NUM`` with
|
||||
``NUM`` being the number of threads you want to use.
|
||||
|
||||
It is therefore a good idea to put this command into your git hook ``.git/hooks/pre-commit``,
|
||||
for example::
|
||||
|
||||
@@ -39,12 +39,12 @@ def test_locking_different_events(event):
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_lock_timeout_steal(event):
|
||||
locking.LOCK_TIMEOUT = 5
|
||||
locking.LOCK_TIMEOUT = 1
|
||||
locking.lock_event(event)
|
||||
with pytest.raises(EventLock.LockTimeoutException):
|
||||
ev = Event.objects.get(id=event.id)
|
||||
locking.lock_event(ev)
|
||||
time.sleep(6)
|
||||
time.sleep(1.5)
|
||||
locking.lock_event(ev)
|
||||
with pytest.raises(EventLock.LockReleaseException):
|
||||
locking.release_event(event)
|
||||
|
||||
@@ -76,6 +76,12 @@ organizer_urls = [
|
||||
]
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def perf_patch(monkeypatch):
|
||||
# Patch out template rendering for performance improvements
|
||||
monkeypatch.setattr("django.template.backends.django.Template.render", lambda *args, **kwargs: "mocked template")
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
@pytest.mark.parametrize("url", [
|
||||
"",
|
||||
@@ -94,7 +100,7 @@ def test_logged_out(client, env, url):
|
||||
|
||||
@pytest.mark.django_db
|
||||
@pytest.mark.parametrize("url", event_urls)
|
||||
def test_wrong_event(client, env, url):
|
||||
def test_wrong_event(perf_patch, client, env, url):
|
||||
client.login(email='dummy@dummy.dummy', password='dummy')
|
||||
response = client.get('/control/event/dummy/dummy/' + url)
|
||||
# These permission violations do not yield a 403 error, but
|
||||
@@ -150,7 +156,7 @@ event_permission_urls = [
|
||||
|
||||
@pytest.mark.django_db
|
||||
@pytest.mark.parametrize("perm,url,code", event_permission_urls)
|
||||
def test_wrong_event_permission(client, env, perm, url, code):
|
||||
def test_wrong_event_permission(perf_patch, client, env, perm, url, code):
|
||||
ep = EventPermission(
|
||||
event=env[0], user=env[1],
|
||||
)
|
||||
@@ -179,7 +185,7 @@ def test_current_permission(client, env):
|
||||
|
||||
@pytest.mark.django_db
|
||||
@pytest.mark.parametrize("perm,url,code", event_permission_urls)
|
||||
def test_correct_event_permission(client, env, perm, url, code):
|
||||
def test_correct_event_permission(perf_patch, client, env, perm, url, code):
|
||||
ep = EventPermission(
|
||||
event=env[0], user=env[1],
|
||||
)
|
||||
@@ -192,7 +198,7 @@ def test_correct_event_permission(client, env, perm, url, code):
|
||||
|
||||
@pytest.mark.django_db
|
||||
@pytest.mark.parametrize("url", organizer_urls)
|
||||
def test_wrong_organizer(client, env, url):
|
||||
def test_wrong_organizer(perf_patch, client, env, url):
|
||||
client.login(email='dummy@dummy.dummy', password='dummy')
|
||||
response = client.get('/control/' + url)
|
||||
# These permission violations do not yield a 403 error, but
|
||||
@@ -207,7 +213,7 @@ organizer_permission_urls = [
|
||||
|
||||
@pytest.mark.django_db
|
||||
@pytest.mark.parametrize("perm,url,code", organizer_permission_urls)
|
||||
def test_wrong_organizer_permission(client, env, perm, url, code):
|
||||
def test_wrong_organizer_permission(perf_patch, client, env, perm, url, code):
|
||||
if perm:
|
||||
op = OrganizerPermission(
|
||||
organizer=env[2], user=env[1],
|
||||
@@ -221,7 +227,7 @@ def test_wrong_organizer_permission(client, env, perm, url, code):
|
||||
|
||||
@pytest.mark.django_db
|
||||
@pytest.mark.parametrize("perm,url,code", organizer_permission_urls)
|
||||
def test_correct_organizer_permission(client, env, perm, url, code):
|
||||
def test_correct_organizer_permission(perf_patch, client, env, perm, url, code):
|
||||
op = OrganizerPermission(
|
||||
organizer=env[2], user=env[1],
|
||||
)
|
||||
|
||||
@@ -13,3 +13,5 @@ MEDIA_ROOT = os.path.join(TEST_DIR, 'media')
|
||||
EMAIL_BACKEND = 'django.core.mail.outbox'
|
||||
|
||||
COMPRESS_ENABLED = COMPRESS_OFFLINE = False
|
||||
|
||||
PASSWORD_HASHERS = ['django.contrib.auth.hashers.MD5PasswordHasher']
|
||||
|
||||
Reference in New Issue
Block a user