Skip to content

Commit 07e7289

Browse files
committed
Switch to github actions
1 parent 8c95555 commit 07e7289

File tree

6 files changed

+182
-18
lines changed

6 files changed

+182
-18
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 }}

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
}

tox.ini

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ deps =
1717
mysql_myisam: mysqlclient==1.4.2.post1
1818
mysql_innodb: mysqlclient==1.4.2.post1
1919

20-
postgres: psycopg2-binary
21-
postgres: psycopg2cffi
20+
!pypy3-postgres: psycopg2-binary
21+
pypy3-postgres: psycopg2cffi
2222
coverage: coverage-enable-subprocess
2323

2424
pytest54: pytest>=5.4,<5.5
@@ -38,7 +38,7 @@ setenv =
3838
coverage: COVERAGE_FILE={toxinidir}/.coverage
3939
coverage: PYTESTDJANGO_COVERAGE_SRC={toxinidir}/
4040

41-
passenv = PYTEST_ADDOPTS TERM
41+
passenv = PYTEST_ADDOPTS TERM TEST_DB_USER TEST_DB_PASSWORD TEST_DB_HOST
4242
usedevelop = True
4343
commands =
4444
coverage: coverage erase

0 commit comments

Comments
 (0)