Skip to content

Commit 10769db

Browse files
Ensure that test doesn't autocreate users before
1 parent 749f76a commit 10769db

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

tin/apps/users/tests.py

+14-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,22 @@
11
from __future__ import annotations
22

3+
import pytest
34
from django.contrib.auth import get_user_model
45
from django.core.management import call_command
56

67

8+
@pytest.mark.no_autocreate_users
79
def test_create_debug_users():
10+
admin = get_user_model().objects.filter(username="admin", is_superuser=True)
11+
student = get_user_model().objects.filter(username="student", is_student=True)
12+
teacher = get_user_model().objects.filter(username="teacher", is_teacher=True)
13+
14+
assert not admin.exists()
15+
assert not teacher.exists()
16+
assert not student.exists()
17+
818
call_command("create_debug_users", noinput=True, verbosity=0)
9-
assert get_user_model().objects.filter(username="admin", is_superuser=True)
10-
assert get_user_model().objects.filter(username="student", is_student=True)
11-
assert get_user_model().objects.filter(username="teacher", is_teacher=True)
19+
20+
assert admin.exists()
21+
assert teacher.exists()
22+
assert student.exists()

tin/tests/fixtures.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,10 @@ def tin_setup(settings, worker_id: str, testrun_uid: str):
3333

3434

3535
@pytest.fixture(autouse=True)
36-
def create_users():
37-
users.add_users_to_database(password=PASSWORD, verbose=False)
36+
def create_users(request):
37+
marker = request.node.get_closest_marker("no_autocreate_users")
38+
if marker is None:
39+
users.add_users_to_database(password=PASSWORD, verbose=False)
3840

3941

4042
@pytest.fixture

0 commit comments

Comments
 (0)