katefike / sage

A personal finance app that's like Mint, but better. It uses a dockerized postfix/dovecot email server. Parses transaction data from alert emails.
MIT License
5 stars 0 forks source link

Run production-safe pytests on production server deployment #97

Open katefike opened 1 year ago

katefike commented 1 year ago
(.venv) kfike@sageProd:~$ ~/sage/.venv/bin/pytest ~/sage/tests -xv
INTERNALERROR> Traceback (most recent call last):
INTERNALERROR>   File "/home/kfike/sage/.venv/lib/python3.10/site-packages/_pytest/main.py", line 266, in wrap_session
INTERNALERROR>     config._do_configure()
INTERNALERROR>   File "/home/kfike/sage/.venv/lib/python3.10/site-packages/_pytest/config/__init__.py", line 1037, in _do_configure
INTERNALERROR>     self.hook.pytest_configure.call_historic(kwargs=dict(config=self))
INTERNALERROR>   File "/home/kfike/sage/.venv/lib/python3.10/site-packages/pluggy/_hooks.py", line 277, in call_historic
INTERNALERROR>     res = self._hookexec(self.name, self.get_hookimpls(), kwargs, False)
INTERNALERROR>   File "/home/kfike/sage/.venv/lib/python3.10/site-packages/pluggy/_manager.py", line 80, in _hookexec
INTERNALERROR>     return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
INTERNALERROR>   File "/home/kfike/sage/.venv/lib/python3.10/site-packages/pluggy/_callers.py", line 60, in _multicall
INTERNALERROR>     return outcome.get_result()
INTERNALERROR>   File "/home/kfike/sage/.venv/lib/python3.10/site-packages/pluggy/_result.py", line 60, in get_result
INTERNALERROR>     raise ex[1].with_traceback(ex[2])
INTERNALERROR>   File "/home/kfike/sage/.venv/lib/python3.10/site-packages/pluggy/_callers.py", line 39, in _multicall
INTERNALERROR>     res = hook_impl.function(*args)
INTERNALERROR>   File "/home/kfike/sage/tests/conftest.py", line 10, in pytest_configure
INTERNALERROR>     assert (
INTERNALERROR> AssertionError: CRITICAL: Only run pytest in the development environment.

The risk of running pytest at all on the prod server is that you truncate all the tables in the DB on accident. This could be avoided by running pytest with markers. Mark the production safe tests. Raise a flag if it's the prod env and attempting to run a development-only test https://docs.pytest.org/en/latest/how-to/mark.html

Another idea is to make the ports different for the prod DB vs the dev DB. Make the dev DB port 6666.