pytest-dotenv icon indicating copy to clipboard operation
pytest-dotenv copied to clipboard

Special casing `PYTHONPATH` in pytest-dotenv?

Open xmo-odoo opened this issue 2 years ago • 0 comments

When using pytest to test utilities (CLI) or a mix of API and utility which require setting PYTHONPATH, the current set of affairs is not great:

  • because pytest_dotenv updates the envvars inside the running process, it's not taken in account by sys.path
  • since 7.0, pytest has added a pythonpath configuration entry but that only updates sys.path, so subprocesses don't take that into account

So if one wants to avoid having to set the envvar externally, one has to hit their head on that wall until they figure that both is necessary.

Having special support for PYTHONPATH was understandably rejected in python-dotenv (https://github.com/theskumar/python-dotenv/pull/36) but I figure pytest-dotenv is a lot more specific, and having a coherent PYTHONPATH & sys.path in test contexts seems a lot more sensible in the context of pytest-ing.

NB: I also opened an issue to see if the Pytest folks would be willing to update the pythonpath feature such that it'd also update the envvar: pytest-dev/pytest#10067

xmo-odoo avatar Jun 22 '22 11:06 xmo-odoo