Skip to content

Commit

Permalink
auto, reuse db, no dist
Browse files Browse the repository at this point in the history
  • Loading branch information
ajay-sentry committed Jun 3, 2024
1 parent 4c42ed2 commit 6211369
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 5 deletions.
15 changes: 14 additions & 1 deletion conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import pytest
import vcr
from django.conf import settings
from pytest_django.fixtures import _set_suffix_to_test_databases
from pytest_django.lazy_django import skip_if_no_django
from shared.reports.resources import Report, ReportFile, ReportLine
from shared.utils.sessions import Session

Expand All @@ -22,6 +24,17 @@ def pytest_configure(config):
pass


@pytest.fixture(scope="session")
def django_db_modify_db_settings_xdist_suffix(request):
skip_if_no_django()

xdist_suffix = getattr(request.config, "workerinput", {}).get("workerid")
if xdist_suffix:
# 'gw0' -> '1', 'gw1' -> '2', ...
suffix = str(int(xdist_suffix.replace("gw", "")) + 1)
_set_suffix_to_test_databases(suffix=suffix)


@pytest.fixture
def codecov_vcr(request):
current_path = Path(request.node.fspath)
Expand All @@ -48,7 +61,7 @@ def mock_redis(mocker):
yield redis_server


@pytest.fixture(scope="class")
@pytest.fixture
def sample_report(request):
report = Report()
first_file = ReportFile("foo/file1.py")
Expand Down
2 changes: 1 addition & 1 deletion pytest.ini
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[pytest]
DJANGO_SETTINGS_MODULE = codecov.settings_dev
addopts = -n 2 -p no:warnings --ignore=shared --ignore-glob=**/test_results*
addopts = --reuse-db -n auto --dist no -p no:warnings --ignore=shared --ignore-glob=**/test_results*
2 changes: 1 addition & 1 deletion upload/tests/test_upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -907,7 +907,7 @@ def test_dispatch_upload_task(self, upload):


class UploadHandlerRouteTest(APITestCase):
@pytest.fixture(scope="function", autouse=True)
@pytest.fixture(autouse=True)
def inject_mocker(self, mocker):
self.mocker = mocker

Expand Down
2 changes: 1 addition & 1 deletion webhook_handlers/tests/test_github.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def __getitem__(self, key):


class GithubWebhookHandlerTests(APITestCase):
@pytest.fixture(scope="function", autouse=True)
@pytest.fixture(autouse=True)
def inject_mocker(request, mocker):
request.mocker = mocker

Expand Down
2 changes: 1 addition & 1 deletion webhook_handlers/tests/test_gitlab_enterprise.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@


class TestGitlabEnterpriseWebhookHandler(APITestCase):
@pytest.fixture(scope="function", autouse=True)
@pytest.fixture(autouse=True)
def inject_mocker(request, mocker):
request.mocker = mocker

Expand Down

0 comments on commit 6211369

Please sign in to comment.