Can you remove the Django dependency for some fold...
# general
f
Can you remove the Django dependency for some folders in a Pants & Django project? For example, for testing a
shared/utils
folder. Unfortunately the django example github does not seem to have such an example. When I tried this naively, it seems pytest always want to import some kind of Django settings for the test.
1
c
Yes, see second note for excluding dependencies here: https://www.pantsbuild.org/docs/targets#dependencies-field
f
Thanks for the reply. But it seems the test still searches for Django even with this change. I'm guessing it's because of the pytest configuration here: https://github.com/pantsbuild/example-django/blob/main/pants.toml#L53
Copy code
[pytest]
...
extra_requirements.add = [
  "pytest-django>=4,<5",
]
b
@fierce-keyboard-91032 I think you're right on the money. That's such a bummer! I searched through the docs of that package and I can't see any way to turn this behavior off. FYI @hundreds-father-404
❤️ 1
h
yeah, if you don't want to always have pytest-django installed, then the alternative is to use it as a normal
python_requirement
. Last paragraph of https://www.pantsbuild.org/docs/python-test-goal#pytest-version-and-plugins
c
Is it possible this is due to
conftest.py
at the root of your test directory triggering
pytest-django
? I don’t think we are seeing this problem. We did have to add something like this to our root
conftest.py
Copy code
def pytest_configure(config):
    if importlib.util.find_spec("path.to.django.consumer") is not None:
        from django.conf import settings

        os.environ["DJANGO_SETTINGS_MODULE"] = "path.to.pytest_settings"
        settings.DATABASES
👀 3
👍 1
f
We don't have a
conftest.py
anywhere in our code yet, so that's not it. Going to try a few things based on the replies here. Thank you very much!
Looks like removing the DJANGO_SETTINGS_MODULE from
pytest.ini
did the trick, thank you!
❤️ 1