From 1a8ed1aaef3ecadf165f7f23c2ef632c6d78d2d1 Mon Sep 17 00:00:00 2001 From: Dani Hodovic Date: Sun, 25 Aug 2019 14:31:59 +0200 Subject: [PATCH] Fix APPS path when using pytest Pytest does not use manage.py when executing tests. This means that the trick we use to append app directories inside of the main project won't work since the logic exists in manage.py. If we instead place the same logic in base.py, things work as expected when running pytest. --- {{cookiecutter.project_slug}}/config/settings/base.py | 4 ++++ {{cookiecutter.project_slug}}/manage.py | 5 ----- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/{{cookiecutter.project_slug}}/config/settings/base.py b/{{cookiecutter.project_slug}}/config/settings/base.py index 7def8f489..18bb6032b 100644 --- a/{{cookiecutter.project_slug}}/config/settings/base.py +++ b/{{cookiecutter.project_slug}}/config/settings/base.py @@ -1,6 +1,7 @@ """ Base settings to build other settings files upon. """ +import sys import environ @@ -8,6 +9,9 @@ ROOT_DIR = ( environ.Path(__file__) - 3 ) # ({{ cookiecutter.project_slug }}/config/settings/base.py - 3 = {{ cookiecutter.project_slug }}/) APPS_DIR = ROOT_DIR.path("{{ cookiecutter.project_slug }}") +# This allows easy placement of apps within the interior +# {{ cookiecutter.project_slug }} directory. +sys.path.append(str(APPS_DIR)) env = environ.Env() diff --git a/{{cookiecutter.project_slug}}/manage.py b/{{cookiecutter.project_slug}}/manage.py index 7e9c99e04..f1c84cace 100755 --- a/{{cookiecutter.project_slug}}/manage.py +++ b/{{cookiecutter.project_slug}}/manage.py @@ -22,9 +22,4 @@ if __name__ == "__main__": raise - # This allows easy placement of apps within the interior - # {{ cookiecutter.project_slug }} directory. - current_path = os.path.dirname(os.path.abspath(__file__)) - sys.path.append(os.path.join(current_path, "{{ cookiecutter.project_slug }}")) - execute_from_command_line(sys.argv)