carltongibson / django-template-partials

Reusable named inline partials for the Django Template Language.
MIT License
444 stars 16 forks source link

tests don't work unless `django-template-partials` is already installed in the venv containing Django. #4

Closed vsajip closed 1 year ago

vsajip commented 1 year ago

Example:

  1. Create a brand new venv and install Django into it.

    $ pew new -p python3.10 django42
    created virtual environment CPython3.10.8.final.0-64 in 1735ms
    ...
    Successfully installed Django-4.2.2 asgiref-3.7.2 sqlparse-0.4.4 typing-extensions-4.6.3
  2. Run the tests with the environment active.

    $ just test
    django-admin test --settings=tests.settings --pythonpath=. 
    Traceback (most recent call last):
     File "/home/vinay/.local/share/virtualenvs/django42/bin/django-admin", line 8, in <module>
       sys.exit(execute_from_command_line())
    ...
    ModuleNotFoundError: No module named 'template_partials'

    The problem is that the tests are relative to the project root, but the source is in src. If we pass PYTHONPATH in the environment, all is well:

    
    $ PYTHONPATH=src just test
    django-admin test --settings=tests.settings --pythonpath=. 
    Found 5 test(s).
    Creating test database for alias 'default'...
    System check identified no issues (0 silenced).
    .....
    ----------------------------------------------------------------------
    Ran 5 tests in 0.008s

OK Destroying test database for alias 'default'...

carltongibson commented 1 year ago

This is a standard feature of the src layout.

https://packaging.python.org/en/latest/discussions/src-layout-vs-flat-layout/#src-layout-vs-flat-layout

After creating the venv, install the package, pip install -e .

Then the just test command runs as expected.

Adding these steps to a Running the tests section of the readme (but just using plain venv) would help folks get started, yes?

vsajip commented 1 year ago

Adding these steps

Yes, I think it would. I guess the src layout is common, but I don't use it myself, and this is the first project where I've hit this snag!