Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
128 changes: 128 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
name: main

on:
push:
branches:
- master
pull_request:
branches:
- master

jobs:
test:
runs-on: ubuntu-20.04
continue-on-error: ${{ matrix.allow_failure }}
steps:
- uses: actions/checkout@v2

- uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python }}

- name: Setup mysql
if: contains(matrix.name, 'mysql')
run: |
sudo systemctl start mysql.service
echo "TEST_DB_USER=root" >> $GITHUB_ENV
echo "TEST_DB_PASSWORD=root" >> $GITHUB_ENV

- name: Setup postgresql
if: contains(matrix.name, 'postgres')
run: |
sudo systemctl start postgresql.service
sudo -u postgres createuser --createdb $USER

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install tox==3.20.0

- name: Run tox
run: tox -e ${{ matrix.name }}

- name: Report coverage
if: contains(matrix.name, 'coverage')
run: |
bash <(curl -s https://codecov.io/bash) -Z -X gcov -X xcode -X gcovout

strategy:
fail-fast: false
matrix:
include:
- name: checkqa,docs
python: 3.8
allow_failure: false

- name: py38-dj31-postgres-xdist-coverage
python: 3.8
allow_failure: false

- name: py37-dj30-mysql_innodb-coverage
python: 3.7
allow_failure: false

- name: py36-dj22-sqlite-xdist-coverage
python: 3.6
allow_failure: false

- name: py37-dj22-sqlite-xdist-coverage
python: 3.7
allow_failure: false

- name: py38-dj30-sqlite-xdist-coverage
python: 3.8
allow_failure: false

- name: py38-dj31-sqlite-xdist-coverage
python: 3.8
allow_failure: false

- name: py38-djmaster-sqlite-coverage
python: 3.8
allow_failure: true

# Explicitly test (older) pytest 5.4.
- name: py35-dj22-postgres-pytest54-coverage
python: 3.5
allow_failure: false

- name: py35-dj22-sqlite_file-coverage
python: 3.5
allow_failure: false

- name: py36-dj31-mysql_myisam-coverage
python: 3.6
allow_failure: false

# pypy3: not included with coverage reports (much slower then).
- name: pypy3-dj22-postgres
python: pypy3
allow_failure: false

deploy:
if: github.event_name == 'push' && startsWith(github.event.ref, 'refs/tags') && github.repository == 'pytest-dev/pytest-django'
runs-on: ubuntu-20.04
needs: [test]

steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0

- uses: actions/setup-python@v2
with:
python-version: "3.8"

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install --upgrade wheel setuptools tox

- name: Build package
run: python setup.py sdist bdist_wheel

- name: Publish package
uses: pypa/gh-action-pypi-publish@1.4.1
with:
user: __token__
password: ${{ secrets.pypi_token }}
56 changes: 28 additions & 28 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,24 +53,24 @@ jobs:
services:
- postgresql

- stage: test_release
python: 3.8
env: TOXENV=py38-dj31-postgres
services:
- postgresql
# - stage: test_release
# python: 3.8
# env: TOXENV=py38-dj31-postgres
# services:
# - postgresql

- stage: release
script: skip
install: skip
after_success: true
deploy:
provider: pypi
user: blueyed
password:
secure: "FY7qbX/N0XRcH8hVk00SsQWvNIkuxKvY7Br4ghRnHvleHG3YulJ7WbJnik+9eoBGeMfJeNyzBfVjpeo1ZIq9IZBiyTdNfG/sZFsC5LOoG/CPxPH3nD9JktI2HoBMnlSbGg/MMHjY+wXuOY647U/3qNedcnQmGztYt6QWi5DRxu8="
on:
tags: true
distributions: "sdist bdist_wheel"
# - stage: release
# script: skip
# install: skip
# after_success: true
# deploy:
# provider: pypi
# user: blueyed
# password:
# secure: "FY7qbX/N0XRcH8hVk00SsQWvNIkuxKvY7Br4ghRnHvleHG3YulJ7WbJnik+9eoBGeMfJeNyzBfVjpeo1ZIq9IZBiyTdNfG/sZFsC5LOoG/CPxPH3nD9JktI2HoBMnlSbGg/MMHjY+wXuOY647U/3qNedcnQmGztYt6QWi5DRxu8="
# on:
# tags: true
# distributions: "sdist bdist_wheel"

# NOTE: does not show up in "allowed failures" section, but is allowed to
# fail (for the "test" stage).
Expand All @@ -82,21 +82,21 @@ stages:
if: tag IS NOT present
- name: test
if: tag IS NOT present
- name: test_release
if: tag IS present
- name: release
if: tag IS present
# - name: test_release
# if: tag IS present
# - name: release
# if: tag IS present

install:
- pip install tox==3.20.0

script:
- tox

after_success:
- |
set -ex
if [[ "${TOXENV%-coverage}" != "$TOXENV" ]]; then
bash <(curl -s https://codecov.io/bash) -Z -X gcov -X xcode -X gcovout
fi
set +ex
# after_success:
# - |
# set -ex
# if [[ "${TOXENV%-coverage}" != "$TOXENV" ]]; then
# bash <(curl -s https://codecov.io/bash) -Z -X gcov -X xcode -X gcovout
# fi
# set +ex
45 changes: 35 additions & 10 deletions pytest_django_test/db_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,44 @@ def __init__(self, status_code, std_out, std_err):
self.std_err = std_err


def run_cmd(*args):
r = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
def run_cmd(*args, env=None):
r = subprocess.Popen(
args,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
env={**os.environ, **(env or {})},
)
stdoutdata, stderrdata = r.communicate()
ret = r.wait()
return CmdResult(ret, stdoutdata, stderrdata)


def run_psql(*args):
env = {}
user = _settings.get("USER")
if user: # pragma: no branch
args = ("-U", user, *args)
password = _settings.get("PASSWORD")
if password: # pragma: no branch
env["PGPASSWORD"] = password
host = _settings.get("HOST")
if host: # pragma: no branch
args = ("-h", host, *args)
return run_cmd("psql", *args, env=env)


def run_mysql(*args):
user = _settings.get("USER", None)
user = _settings.get("USER")
if user: # pragma: no branch
args = ("-u", user) + tuple(args)
args = ("mysql",) + tuple(args)
return run_cmd(*args)
args = ("-u", user, *args)
password = _settings.get("PASSWORD")
if password: # pragma: no branch
# Note: "-ppassword" must be a single argument.
args = ("-p" + password, *args)
host = _settings.get("HOST")
if host: # pragma: no branch
args = ("-h", host, *args)
return run_cmd("mysql", *args)


def skip_if_sqlite_in_memory():
Expand All @@ -73,7 +98,7 @@ def drop_database(db_suffix=None):
db_engine = get_db_engine()

if db_engine == "postgresql":
r = run_cmd("psql", "postgres", "-c", "DROP DATABASE %s" % name)
r = run_psql("postgres", "-c", "DROP DATABASE %s" % name)
assert "DROP DATABASE" in force_str(
r.std_out
) or "does not exist" in force_str(r.std_err)
Expand All @@ -95,7 +120,7 @@ def db_exists(db_suffix=None):
db_engine = get_db_engine()

if db_engine == "postgresql":
r = run_cmd("psql", name, "-c", "SELECT 1")
r = run_psql(name, "-c", "SELECT 1")
return r.status_code == 0

if db_engine == "mysql":
Expand All @@ -112,7 +137,7 @@ def mark_database():
db_engine = get_db_engine()

if db_engine == "postgresql":
r = run_cmd("psql", TEST_DB_NAME, "-c", "CREATE TABLE mark_table();")
r = run_psql(TEST_DB_NAME, "-c", "CREATE TABLE mark_table();")
assert r.status_code == 0
return

Expand All @@ -137,7 +162,7 @@ def mark_exists():
db_engine = get_db_engine()

if db_engine == "postgresql":
r = run_cmd("psql", TEST_DB_NAME, "-c", "SELECT 1 FROM mark_table")
r = run_psql(TEST_DB_NAME, "-c", "SELECT 1 FROM mark_table")

# When something pops out on std_out, we are good
return bool(r.std_out)
Expand Down
7 changes: 5 additions & 2 deletions pytest_django_test/settings_mysql_innodb.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
from os import environ

from .settings_base import * # noqa: F401 F403

DATABASES = {
"default": {
"ENGINE": "django.db.backends.mysql",
"NAME": "pytest_django_should_never_get_accessed",
"HOST": "localhost",
"USER": "root",
"USER": environ.get("TEST_DB_USER", "root"),
"PASSWORD": environ.get("TEST_DB_PASSWORD", ""),
"HOST": environ.get("TEST_DB_HOST", "localhost"),
"OPTIONS": {"init_command": "SET default_storage_engine=InnoDB"},
}
}
7 changes: 5 additions & 2 deletions pytest_django_test/settings_mysql_myisam.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
from os import environ

from .settings_base import * # noqa: F401 F403

DATABASES = {
"default": {
"ENGINE": "django.db.backends.mysql",
"NAME": "pytest_django_should_never_get_accessed",
"HOST": "localhost",
"USER": "root",
"USER": environ.get("TEST_DB_USER", "root"),
"PASSWORD": environ.get("TEST_DB_PASSWORD", ""),
"HOST": environ.get("TEST_DB_HOST", "localhost"),
"OPTIONS": {"init_command": "SET default_storage_engine=MyISAM"},
}
}
7 changes: 6 additions & 1 deletion pytest_django_test/settings_postgres.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from os import environ

from .settings_base import * # noqa: F401 F403

# PyPy compatibility
Expand All @@ -13,5 +15,8 @@
"default": {
"ENGINE": "django.db.backends.postgresql",
"NAME": "pytest_django_should_never_get_accessed",
}
"USER": environ.get("TEST_DB_USER", ""),
"PASSWORD": environ.get("TEST_DB_PASSWORD", ""),
"HOST": environ.get("TEST_DB_HOST", ""),
},
}
2 changes: 1 addition & 1 deletion tests/test_db_access_in_repr.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def test_via_db_fixture(db):
"tpkg/test_the_test.py:8: ",
'self = *RuntimeError*Database access not allowed*',
"E *DoesNotExist: Item matching query does not exist.",
"* 2 failed in *",
"* 2 failed*",
])
assert "INTERNALERROR" not in str(result.stdout) + str(result.stderr)
assert result.ret == 1
2 changes: 1 addition & 1 deletion tests/test_db_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ def test_inner_migrations():
)
assert result.ret == 0
assert "Operations to perform:" not in result.stdout.str()
result.stdout.fnmatch_lines(["*= 1 passed in *"])
result.stdout.fnmatch_lines(["*= 1 passed*"])

def test_migrations_run(self, django_testdir):
testdir = django_testdir
Expand Down
8 changes: 4 additions & 4 deletions tests/test_django_configurations.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def test_settings():
result = testdir.runpytest_subprocess()
result.stdout.fnmatch_lines([
'django: settings: tpkg.settings_env (from env), configuration: MySettings (from env)',
"* 1 passed in*",
"* 1 passed*",
])
assert result.ret == 0

Expand Down Expand Up @@ -73,7 +73,7 @@ def test_ds():
result = testdir.runpytest_subprocess()
result.stdout.fnmatch_lines([
'django: settings: tpkg.settings_env (from env), configuration: MySettings (from env)',
"* 1 passed in*",
"* 1 passed*",
])
assert result.ret == 0

Expand Down Expand Up @@ -103,7 +103,7 @@ def test_ds():
result = testdir.runpytest_subprocess()
result.stdout.fnmatch_lines([
'django: settings: tpkg.settings_ini (from ini), configuration: MySettings (from ini)',
"* 1 passed in*",
"* 1 passed*",
])
assert result.ret == 0

Expand Down Expand Up @@ -135,6 +135,6 @@ def test_ds():
result.stdout.fnmatch_lines([
'django: settings: tpkg.settings_opt (from option),'
' configuration: MySettings (from option)',
"* 1 passed in*",
"* 1 passed*",
])
assert result.ret == 0
Loading