EDIT: Ignore this, Pants is working fine :smile: ...
# general
s
EDIT: Ignore this, Pants is working fine 😄 Just a basic fact or rather something I’d like to have someone’s opinion on: • When you have tests and a
conftest.py
in one directory with a BUILD-file and in a deeper level you have more tests with their own BUILD-file, the usual “pytest” behavior would be to go up the folders and use all
conftest.py
-Files up the tree. This is kind of obsolete with Pants, right? So I could either import the stuff I need from
conftest.py
above into my tests, or define the
python_test_utils
from “above” in my BUILD-file. Does this make sense? 😅
1
r
I'm 99% sure that you can keep using the same conftest down below in sub directories. You just need to define
python_test_utils
once at the top where the
conftest.py
lives.
s
Thank you! I was just wondering 🤔 Having some weird issues where the development database is used instead of the testing but just for some tests. -> Investigating 🕵️
Oh nevermind, this was me messing up my
conftest.py
😩
🤗 1
h
You can have nested contest.py as usual, it should work?
1
s
Yes sorry @happy-kitchen-89482 it does, this was just me finding an old but unresolved bug in
pytest-django
=> https://github.com/pytest-dev/pytest-django/issues/643
We use this
conftest.py
in the root of our sources now:
Copy code
@pytest.fixture(scope="session")
def django_db_modify_db_settings():
    from django.conf import settings

    pants_execution_slot = os.environ.get("PANTS_EXECUTION_SLOT", "")

    default_test_db = settings.DATABASES["default"]
    default_test_db["NAME"] = f"osiris_test{pants_execution_slot}"
Seems to work fine 👍 (important: this only works with
pytest-django
)