fix(django): usage with class based tests (#12)

This commit is contained in:
Max Schmitt 2020-10-03 18:09:13 +02:00 коммит произвёл GitHub
Родитель 20a6e7c6d5
Коммит 779b44a9ed
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
7 изменённых файлов: 132 добавлений и 0 удалений

4
.github/workflows/ci.yml поставляемый
Просмотреть файл

@ -34,6 +34,10 @@ jobs:
- name: Test
if: ${{ matrix.os != 'ubuntu-latest' }}
run: pytest --cov=pytest_playwright --cov-report xml
env:
DJANGO_SETTINGS_MODULE: tests.assets.django.settings
- name: Test on Linux
if: ${{ matrix.os == 'ubuntu-latest' }}
run: xvfb-run pytest --cov=pytest_playwright --cov-report xml
env:
DJANGO_SETTINGS_MODULE: tests.assets.django.settings

Просмотреть файл

@ -8,3 +8,4 @@ twisted==20.3.0
wheel==0.34.2
flake8==3.8.3
pre-commit==2.6.0
Django==3.1.2

Просмотреть файл

@ -159,6 +159,11 @@ def is_chromium(browser_name: str) -> bool:
return browser_name == "chromium"
@pytest.fixture(scope="session")
def browser_name() -> None:
return None
def pytest_addoption(parser: Any) -> None:
group = parser.getgroup("playwright", "Playwright")
group.addoption(

Просмотреть файл

Просмотреть файл

@ -0,0 +1,102 @@
import os
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/2.2/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = "123"
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
ALLOWED_HOSTS = []
# Application definition
INSTALLED_APPS = [
"django.contrib.admin",
"django.contrib.auth",
"django.contrib.contenttypes",
"django.contrib.sessions",
"django.contrib.messages",
"django.contrib.staticfiles",
]
MIDDLEWARE = [
"django.middleware.security.SecurityMiddleware",
"django.contrib.sessions.middleware.SessionMiddleware",
"django.middleware.common.CommonMiddleware",
"django.middleware.csrf.CsrfViewMiddleware",
"django.contrib.auth.middleware.AuthenticationMiddleware",
"django.contrib.messages.middleware.MessageMiddleware",
"django.middleware.clickjacking.XFrameOptionsMiddleware",
]
ROOT_URLCONF = "proj1.urls"
TEMPLATES = [
{
"BACKEND": "django.template.backends.django.DjangoTemplates",
"DIRS": [],
"APP_DIRS": True,
"OPTIONS": {
"context_processors": [
"django.template.context_processors.debug",
"django.template.context_processors.request",
"django.contrib.auth.context_processors.auth",
"django.contrib.messages.context_processors.messages",
],
},
},
]
WSGI_APPLICATION = "proj1.wsgi.application"
# Database
# https://docs.djangoproject.com/en/2.2/ref/settings/#databases
DATABASES = {
"default": {
"ENGINE": "django.db.backends.sqlite3",
"NAME": os.path.join(BASE_DIR, "db.sqlite3"),
}
}
# Password validation
# https://docs.djangoproject.com/en/2.2/ref/settings/#auth-password-validators
AUTH_PASSWORD_VALIDATORS = [
{
"NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator",
},
{"NAME": "django.contrib.auth.password_validation.MinimumLengthValidator"},
{"NAME": "django.contrib.auth.password_validation.CommonPasswordValidator"},
{"NAME": "django.contrib.auth.password_validation.NumericPasswordValidator"},
]
# Internationalization
# https://docs.djangoproject.com/en/2.2/topics/i18n/
LANGUAGE_CODE = "en-us"
TIME_ZONE = "UTC"
USE_I18N = True
USE_L10N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/2.2/howto/static-files/
STATIC_URL = "/static/"

Просмотреть файл

@ -0,0 +1,6 @@
from django.contrib import admin
from django.urls import path
urlpatterns = [
path("admin/", admin.site.urls),
]

Просмотреть файл

@ -177,3 +177,17 @@ def test_invalid_browser_name(testdir: Any) -> None:
result = testdir.runpytest("--browser", "test123")
result.assert_outcomes(errors=1)
assert "'test123' is not allowed" in "\n".join(result.outlines)
def test_django(testdir: Any) -> None:
testdir.makepyfile(
"""
from django.test import TestCase
class Proj1Test(TestCase):
def test_one(self):
self.assertTrue(True)
"""
)
result = testdir.runpytest()
result.assert_outcomes(passed=1)