Skip to content

Commit 86af979

Browse files
Merge pull request #741 from python-discord/speedup-tests
Remove IP Specification From Compose Ports
2 parents 1ca8b4d + 1122f5a commit 86af979

File tree

4 files changed

+20
-9
lines changed

4 files changed

+20
-9
lines changed

.github/workflows/lint-test.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@ jobs:
9797
- name: Migrations and run tests with coverage.py
9898
run: |
9999
python manage.py makemigrations --check
100-
python manage.py migrate
101100
coverage run manage.py test --no-input
102101
coverage report -m
103102
env:

docker-compose.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@
88
# and additionally use the Django development server which is
99
# unsuitable for production.
1010

11-
version: "3.6"
11+
version: "3.8"
1212
services:
1313
postgres:
1414
image: postgres:13-alpine
1515
ports:
16-
- "127.0.0.1:7777:5432"
16+
- "7777:5432"
1717
environment:
1818
POSTGRES_DB: pysite
1919
POSTGRES_PASSWORD: pysite
@@ -38,7 +38,7 @@ services:
3838
- admin.web
3939
- staff.web
4040
ports:
41-
- "127.0.0.1:8000:8000"
41+
- "8000:8000"
4242
depends_on:
4343
postgres:
4444
condition: service_healthy

manage.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,13 +95,15 @@ def set_dev_site_name() -> None:
9595
name="pythondiscord.local:8000"
9696
)
9797

98-
def prepare_server(self) -> None:
99-
"""Perform preparation tasks before running the server."""
98+
def prepare_environment(self) -> None:
99+
"""Perform common preparation tasks."""
100100
django.setup()
101101

102102
print("Applying migrations.")
103103
call_command("migrate", verbosity=self.verbosity)
104104

105+
def prepare_server(self) -> None:
106+
"""Preform runserver-specific preparation tasks."""
105107
if self.debug:
106108
# In Production, collectstatic is ran in the Docker image
107109
print("Collecting static files.")
@@ -121,6 +123,7 @@ def run_server(self) -> None:
121123

122124
# Prevent preparing twice when in dev mode due to reloader
123125
if not self.debug or in_reloader:
126+
self.prepare_environment()
124127
self.prepare_server()
125128

126129
print("Starting server.")
@@ -148,6 +151,11 @@ def run_server(self) -> None:
148151
# Run gunicorn for the production server.
149152
gunicorn.app.wsgiapp.run()
150153

154+
def run_tests(self) -> None:
155+
"""Prepare and run the test suite."""
156+
self.prepare_environment()
157+
call_command(*sys.argv[1:])
158+
151159

152160
def clean_up_static_files(build_folder: Path) -> None:
153161
"""Recursively loop over the build directory and fix links."""
@@ -168,8 +176,12 @@ def clean_up_static_files(build_folder: Path) -> None:
168176
def main() -> None:
169177
"""Entry point for Django management script."""
170178
# Use the custom site manager for launching the server
171-
if len(sys.argv) > 1 and sys.argv[1] == "run":
172-
SiteManager(sys.argv).run_server()
179+
if len(sys.argv) > 1 and sys.argv[1] in ("run", "test"):
180+
manager = SiteManager(sys.argv)
181+
if sys.argv[1] == "run":
182+
manager.run_server()
183+
elif sys.argv[1] == "test":
184+
manager.run_tests()
173185

174186
# Pass any others directly to standard management commands
175187
else:

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ start = "python manage.py run --debug"
5151
makemigrations = "python manage.py makemigrations"
5252
django_shell = "python manage.py shell"
5353
test = "coverage run manage.py test"
54-
coverage = "coverage run manage.py test --no-input; coverage report -m"
54+
coverage = "coverage run manage.py test --no-input && coverage report -m"
5555
report = "coverage report -m"
5656
lint = "pre-commit run --all-files"
5757
precommit = "pre-commit install"

0 commit comments

Comments
 (0)