aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar MarkKoz <[email protected]>2022-06-01 14:03:21 -0700
committerGravatar MarkKoz <[email protected]>2022-06-01 14:03:21 -0700
commitb1e425312f0e62a23c7baa168558278b18ce35a9 (patch)
treef348629cb9c1787ac2e9b7655e588d1e82a582fa
parentIgnore deprecation warning from Sentry's Falcon integration (diff)
Import the WSGI app via the config during tests
Relying more on gunicorn and its config parsing will avoid discrepancies between the test and production environments.
-rw-r--r--tests/gunicorn_utils.py16
1 files changed, 7 insertions, 9 deletions
diff --git a/tests/gunicorn_utils.py b/tests/gunicorn_utils.py
index b417b1b..f5dae7a 100644
--- a/tests/gunicorn_utils.py
+++ b/tests/gunicorn_utils.py
@@ -3,10 +3,10 @@ import contextlib
import multiprocessing
from typing import Iterator
-from gunicorn.app.base import Application
+from gunicorn.app.wsgiapp import WSGIApplication
-class _StandaloneApplication(Application):
+class _StandaloneApplication(WSGIApplication):
def __init__(self, config_path: str = None, **kwargs):
self.config_path = config_path
self.options = kwargs
@@ -14,19 +14,17 @@ class _StandaloneApplication(Application):
super().__init__()
def init(self, parser, opts, args):
- pass
-
- def load(self):
- from snekbox.api import SnekAPI
- return SnekAPI()
+ """Patch `opts` to simulate the config path being passed as a command-line argument."""
+ super().init(parser, opts, args)
+ opts.config = self.config_path
def load_config(self):
+ """Set the option kwargs in the config, then load the config as usual."""
for key, value in self.options.items():
if key in self.cfg.settings and value is not None:
self.cfg.set(key.lower(), value)
- if self.config_path:
- self.load_config_from_file(self.config_path)
+ super().load_config()
def _proc_target(config_path: str, event: multiprocessing.Event, **kwargs) -> None: