Skip to content

Commit 5551aea

Browse files
authored
Merge pull request #876 from bluetech/github-actions
Switch to github actions
2 parents 7589394 + 18f78ff commit 5551aea

14 files changed

+227
-63
lines changed

.github/workflows/main.yml

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
name: main
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
pull_request:
8+
branches:
9+
- master
10+
11+
jobs:
12+
test:
13+
runs-on: ubuntu-20.04
14+
continue-on-error: ${{ matrix.allow_failure }}
15+
steps:
16+
- uses: actions/checkout@v2
17+
18+
- uses: actions/setup-python@v2
19+
with:
20+
python-version: ${{ matrix.python }}
21+
22+
- name: Setup mysql
23+
if: contains(matrix.name, 'mysql')
24+
run: |
25+
sudo systemctl start mysql.service
26+
echo "TEST_DB_USER=root" >> $GITHUB_ENV
27+
echo "TEST_DB_PASSWORD=root" >> $GITHUB_ENV
28+
29+
- name: Setup postgresql
30+
if: contains(matrix.name, 'postgres')
31+
run: |
32+
sudo systemctl start postgresql.service
33+
sudo -u postgres createuser --createdb $USER
34+
35+
- name: Install dependencies
36+
run: |
37+
python -m pip install --upgrade pip
38+
pip install tox==3.20.0
39+
40+
- name: Run tox
41+
run: tox -e ${{ matrix.name }}
42+
43+
- name: Report coverage
44+
if: contains(matrix.name, 'coverage')
45+
run: |
46+
bash <(curl -s https://codecov.io/bash) -Z -X gcov -X xcode -X gcovout
47+
48+
strategy:
49+
fail-fast: false
50+
matrix:
51+
include:
52+
- name: checkqa,docs
53+
python: 3.8
54+
allow_failure: false
55+
56+
- name: py38-dj31-postgres-xdist-coverage
57+
python: 3.8
58+
allow_failure: false
59+
60+
- name: py37-dj30-mysql_innodb-coverage
61+
python: 3.7
62+
allow_failure: false
63+
64+
- name: py36-dj22-sqlite-xdist-coverage
65+
python: 3.6
66+
allow_failure: false
67+
68+
- name: py37-dj22-sqlite-xdist-coverage
69+
python: 3.7
70+
allow_failure: false
71+
72+
- name: py38-dj30-sqlite-xdist-coverage
73+
python: 3.8
74+
allow_failure: false
75+
76+
- name: py38-dj31-sqlite-xdist-coverage
77+
python: 3.8
78+
allow_failure: false
79+
80+
- name: py38-djmaster-sqlite-coverage
81+
python: 3.8
82+
allow_failure: true
83+
84+
# Explicitly test (older) pytest 5.4.
85+
- name: py35-dj22-postgres-pytest54-coverage
86+
python: 3.5
87+
allow_failure: false
88+
89+
- name: py35-dj22-sqlite_file-coverage
90+
python: 3.5
91+
allow_failure: false
92+
93+
- name: py36-dj31-mysql_myisam-coverage
94+
python: 3.6
95+
allow_failure: false
96+
97+
# pypy3: not included with coverage reports (much slower then).
98+
- name: pypy3-dj22-postgres
99+
python: pypy3
100+
allow_failure: false
101+
102+
deploy:
103+
if: github.event_name == 'push' && startsWith(github.event.ref, 'refs/tags') && github.repository == 'pytest-dev/pytest-django'
104+
runs-on: ubuntu-20.04
105+
needs: [test]
106+
107+
steps:
108+
- uses: actions/checkout@v2
109+
with:
110+
fetch-depth: 0
111+
112+
- uses: actions/setup-python@v2
113+
with:
114+
python-version: "3.8"
115+
116+
- name: Install dependencies
117+
run: |
118+
python -m pip install --upgrade pip
119+
pip install --upgrade wheel setuptools tox
120+
121+
- name: Build package
122+
run: python setup.py sdist bdist_wheel
123+
124+
- name: Publish package
125+
uses: pypa/gh-action-pypi-publish@1.4.1
126+
with:
127+
user: __token__
128+
password: ${{ secrets.pypi_token }}

.travis.yml

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -53,24 +53,24 @@ jobs:
5353
services:
5454
- postgresql
5555

56-
- stage: test_release
57-
python: 3.8
58-
env: TOXENV=py38-dj31-postgres
59-
services:
60-
- postgresql
56+
# - stage: test_release
57+
# python: 3.8
58+
# env: TOXENV=py38-dj31-postgres
59+
# services:
60+
# - postgresql
6161

62-
- stage: release
63-
script: skip
64-
install: skip
65-
after_success: true
66-
deploy:
67-
provider: pypi
68-
user: blueyed
69-
password:
70-
secure: "FY7qbX/N0XRcH8hVk00SsQWvNIkuxKvY7Br4ghRnHvleHG3YulJ7WbJnik+9eoBGeMfJeNyzBfVjpeo1ZIq9IZBiyTdNfG/sZFsC5LOoG/CPxPH3nD9JktI2HoBMnlSbGg/MMHjY+wXuOY647U/3qNedcnQmGztYt6QWi5DRxu8="
71-
on:
72-
tags: true
73-
distributions: "sdist bdist_wheel"
62+
# - stage: release
63+
# script: skip
64+
# install: skip
65+
# after_success: true
66+
# deploy:
67+
# provider: pypi
68+
# user: blueyed
69+
# password:
70+
# secure: "FY7qbX/N0XRcH8hVk00SsQWvNIkuxKvY7Br4ghRnHvleHG3YulJ7WbJnik+9eoBGeMfJeNyzBfVjpeo1ZIq9IZBiyTdNfG/sZFsC5LOoG/CPxPH3nD9JktI2HoBMnlSbGg/MMHjY+wXuOY647U/3qNedcnQmGztYt6QWi5DRxu8="
71+
# on:
72+
# tags: true
73+
# distributions: "sdist bdist_wheel"
7474

7575
# NOTE: does not show up in "allowed failures" section, but is allowed to
7676
# fail (for the "test" stage).
@@ -82,21 +82,21 @@ stages:
8282
if: tag IS NOT present
8383
- name: test
8484
if: tag IS NOT present
85-
- name: test_release
86-
if: tag IS present
87-
- name: release
88-
if: tag IS present
85+
# - name: test_release
86+
# if: tag IS present
87+
# - name: release
88+
# if: tag IS present
8989

9090
install:
9191
- pip install tox==3.20.0
9292

9393
script:
9494
- tox
9595

96-
after_success:
97-
- |
98-
set -ex
99-
if [[ "${TOXENV%-coverage}" != "$TOXENV" ]]; then
100-
bash <(curl -s https://codecov.io/bash) -Z -X gcov -X xcode -X gcovout
101-
fi
102-
set +ex
96+
# after_success:
97+
# - |
98+
# set -ex
99+
# if [[ "${TOXENV%-coverage}" != "$TOXENV" ]]; then
100+
# bash <(curl -s https://codecov.io/bash) -Z -X gcov -X xcode -X gcovout
101+
# fi
102+
# set +ex

pytest_django_test/db_helpers.py

Lines changed: 35 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,19 +38,44 @@ def __init__(self, status_code, std_out, std_err):
3838
self.std_err = std_err
3939

4040

41-
def run_cmd(*args):
42-
r = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
41+
def run_cmd(*args, env=None):
42+
r = subprocess.Popen(
43+
args,
44+
stdout=subprocess.PIPE,
45+
stderr=subprocess.PIPE,
46+
env={**os.environ, **(env or {})},
47+
)
4348
stdoutdata, stderrdata = r.communicate()
4449
ret = r.wait()
4550
return CmdResult(ret, stdoutdata, stderrdata)
4651

4752

53+
def run_psql(*args):
54+
env = {}
55+
user = _settings.get("USER")
56+
if user: # pragma: no branch
57+
args = ("-U", user, *args)
58+
password = _settings.get("PASSWORD")
59+
if password: # pragma: no branch
60+
env["PGPASSWORD"] = password
61+
host = _settings.get("HOST")
62+
if host: # pragma: no branch
63+
args = ("-h", host, *args)
64+
return run_cmd("psql", *args, env=env)
65+
66+
4867
def run_mysql(*args):
49-
user = _settings.get("USER", None)
68+
user = _settings.get("USER")
5069
if user: # pragma: no branch
51-
args = ("-u", user) + tuple(args)
52-
args = ("mysql",) + tuple(args)
53-
return run_cmd(*args)
70+
args = ("-u", user, *args)
71+
password = _settings.get("PASSWORD")
72+
if password: # pragma: no branch
73+
# Note: "-ppassword" must be a single argument.
74+
args = ("-p" + password, *args)
75+
host = _settings.get("HOST")
76+
if host: # pragma: no branch
77+
args = ("-h", host, *args)
78+
return run_cmd("mysql", *args)
5479

5580

5681
def skip_if_sqlite_in_memory():
@@ -73,7 +98,7 @@ def drop_database(db_suffix=None):
7398
db_engine = get_db_engine()
7499

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

97122
if db_engine == "postgresql":
98-
r = run_cmd("psql", name, "-c", "SELECT 1")
123+
r = run_psql(name, "-c", "SELECT 1")
99124
return r.status_code == 0
100125

101126
if db_engine == "mysql":
@@ -112,7 +137,7 @@ def mark_database():
112137
db_engine = get_db_engine()
113138

114139
if db_engine == "postgresql":
115-
r = run_cmd("psql", TEST_DB_NAME, "-c", "CREATE TABLE mark_table();")
140+
r = run_psql(TEST_DB_NAME, "-c", "CREATE TABLE mark_table();")
116141
assert r.status_code == 0
117142
return
118143

@@ -137,7 +162,7 @@ def mark_exists():
137162
db_engine = get_db_engine()
138163

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

142167
# When something pops out on std_out, we are good
143168
return bool(r.std_out)
Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
1+
from os import environ
2+
13
from .settings_base import * # noqa: F401 F403
24

35
DATABASES = {
46
"default": {
57
"ENGINE": "django.db.backends.mysql",
68
"NAME": "pytest_django_should_never_get_accessed",
7-
"HOST": "localhost",
8-
"USER": "root",
9+
"USER": environ.get("TEST_DB_USER", "root"),
10+
"PASSWORD": environ.get("TEST_DB_PASSWORD", ""),
11+
"HOST": environ.get("TEST_DB_HOST", "localhost"),
912
"OPTIONS": {"init_command": "SET default_storage_engine=InnoDB"},
1013
}
1114
}
Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
1+
from os import environ
2+
13
from .settings_base import * # noqa: F401 F403
24

35
DATABASES = {
46
"default": {
57
"ENGINE": "django.db.backends.mysql",
68
"NAME": "pytest_django_should_never_get_accessed",
7-
"HOST": "localhost",
8-
"USER": "root",
9+
"USER": environ.get("TEST_DB_USER", "root"),
10+
"PASSWORD": environ.get("TEST_DB_PASSWORD", ""),
11+
"HOST": environ.get("TEST_DB_HOST", "localhost"),
912
"OPTIONS": {"init_command": "SET default_storage_engine=MyISAM"},
1013
}
1114
}

pytest_django_test/settings_postgres.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from os import environ
2+
13
from .settings_base import * # noqa: F401 F403
24

35
# PyPy compatibility
@@ -13,5 +15,8 @@
1315
"default": {
1416
"ENGINE": "django.db.backends.postgresql",
1517
"NAME": "pytest_django_should_never_get_accessed",
16-
}
18+
"USER": environ.get("TEST_DB_USER", ""),
19+
"PASSWORD": environ.get("TEST_DB_PASSWORD", ""),
20+
"HOST": environ.get("TEST_DB_HOST", ""),
21+
},
1722
}

tests/test_db_access_in_repr.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def test_via_db_fixture(db):
2121
"tpkg/test_the_test.py:8: ",
2222
'self = *RuntimeError*Database access not allowed*',
2323
"E *DoesNotExist: Item matching query does not exist.",
24-
"* 2 failed in *",
24+
"* 2 failed*",
2525
])
2626
assert "INTERNALERROR" not in str(result.stdout) + str(result.stderr)
2727
assert result.ret == 1

tests/test_db_setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,7 @@ def test_inner_migrations():
480480
)
481481
assert result.ret == 0
482482
assert "Operations to perform:" not in result.stdout.str()
483-
result.stdout.fnmatch_lines(["*= 1 passed in *"])
483+
result.stdout.fnmatch_lines(["*= 1 passed*"])
484484

485485
def test_migrations_run(self, django_testdir):
486486
testdir = django_testdir

tests/test_django_configurations.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def test_settings():
4242
result = testdir.runpytest_subprocess()
4343
result.stdout.fnmatch_lines([
4444
'django: settings: tpkg.settings_env (from env), configuration: MySettings (from env)',
45-
"* 1 passed in*",
45+
"* 1 passed*",
4646
])
4747
assert result.ret == 0
4848

@@ -73,7 +73,7 @@ def test_ds():
7373
result = testdir.runpytest_subprocess()
7474
result.stdout.fnmatch_lines([
7575
'django: settings: tpkg.settings_env (from env), configuration: MySettings (from env)',
76-
"* 1 passed in*",
76+
"* 1 passed*",
7777
])
7878
assert result.ret == 0
7979

@@ -103,7 +103,7 @@ def test_ds():
103103
result = testdir.runpytest_subprocess()
104104
result.stdout.fnmatch_lines([
105105
'django: settings: tpkg.settings_ini (from ini), configuration: MySettings (from ini)',
106-
"* 1 passed in*",
106+
"* 1 passed*",
107107
])
108108
assert result.ret == 0
109109

@@ -135,6 +135,6 @@ def test_ds():
135135
result.stdout.fnmatch_lines([
136136
'django: settings: tpkg.settings_opt (from option),'
137137
' configuration: MySettings (from option)',
138-
"* 1 passed in*",
138+
"* 1 passed*",
139139
])
140140
assert result.ret == 0

0 commit comments

Comments
 (0)