https://pantsbuild.org/ logo
#general
Title
# general
s

strong-toothbrush-37759

03/19/2022, 9:16 PM
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

refined-addition-53644

03/19/2022, 9:28 PM
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

strong-toothbrush-37759

03/19/2022, 9:32 PM
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

happy-kitchen-89482

03/19/2022, 10:02 PM
You can have nested contest.py as usual, it should work?
1
s

strong-toothbrush-37759

03/20/2022, 11:53 AM
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
)
6 Views