From b94d05902bcbe11a61246b54a58d586cfe7bb455 Mon Sep 17 00:00:00 2001 From: Gabriel Augendre Date: Fri, 25 Dec 2020 14:46:32 +0100 Subject: [PATCH] Fix tests --- .builds/freebsd.yml | 1 - articles/tests/conftest.py | 7 +++++++ blog/settings.py | 10 +--------- docker/runtests.sh | 4 ++-- 4 files changed, 10 insertions(+), 12 deletions(-) diff --git a/.builds/freebsd.yml b/.builds/freebsd.yml index 971d7a9..b25bbe1 100644 --- a/.builds/freebsd.yml +++ b/.builds/freebsd.yml @@ -10,7 +10,6 @@ secrets: - ea931da1-9acd-47b0-b6c9-52b8b61c4647 # Ansible hosts file - 5c948915-48c2-4542-8fc1-a5676f4d7126 # Deploy SSH key environment: - TESTING: true POETRY_VERSION: 1.1.4 tasks: - install_poetry: | diff --git a/articles/tests/conftest.py b/articles/tests/conftest.py index ea2fc9a..be3b7c6 100644 --- a/articles/tests/conftest.py +++ b/articles/tests/conftest.py @@ -1,4 +1,5 @@ import pytest +from django.core.management import call_command from django.utils import timezone from articles.models import Article, User @@ -40,3 +41,9 @@ def unpublished_article(author: User) -> Article: slug="some-draft-article-slug", content="## some draft article markdown\n\n[a draft article link](https://article.com)", ) + + +@pytest.fixture(autouse=True, scope="session") +def collect_static(): + call_command("collectstatic", "--no-input", "--clear") + call_command("assets", "build", "--manifest", "django") diff --git a/blog/settings.py b/blog/settings.py index a3786f3..83e975d 100644 --- a/blog/settings.py +++ b/blog/settings.py @@ -43,7 +43,6 @@ EMAIL_BACKEND = "anymail.backends.mailgun.EmailBackend" # SECURITY WARNING: don't run with debug turned on in production! DEBUG = os.getenv("DEBUG", "true").lower() == "true" -TESTING = os.getenv("TESTING", "false").lower() == "true" ALLOWED_HOSTS = ["localhost"] # Required for healthcheck if DEBUG: @@ -161,14 +160,7 @@ USE_TZ = True STATIC_URL = "/static/" STATIC_ROOT = BASE_DIR / "staticfiles" -if TESTING: - # ManifestStaticFilesStorage requires collectstatic to be run - # and collectstatic is not run for tests - STATICFILES_STORAGE = "django.contrib.staticfiles.storage.StaticFilesStorage" -else: - STATICFILES_STORAGE = ( - "django.contrib.staticfiles.storage.ManifestStaticFilesStorage" - ) +STATICFILES_STORAGE = "django.contrib.staticfiles.storage.StaticFilesStorage" STATICFILES_FINDERS = [ "django.contrib.staticfiles.finders.FileSystemFinder", diff --git a/docker/runtests.sh b/docker/runtests.sh index 333650c..08cae94 100755 --- a/docker/runtests.sh +++ b/docker/runtests.sh @@ -1,5 +1,5 @@ #!/bin/sh set -euxo pipefail -TESTING=true python -m pytest +python -m pytest pre-commit run --all-files -TESTING=true python manage.py makemigrations --check +python manage.py makemigrations --check