Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run production-safe pytests on production server deployment #97

Open
katefike opened this issue Jul 4, 2023 · 0 comments
Open

Run production-safe pytests on production server deployment #97

katefike opened this issue Jul 4, 2023 · 0 comments

Comments

@katefike
Copy link
Owner

katefike commented Jul 4, 2023

(.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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

When branches are created from issues, their pull requests are automatically linked.

1 participant