HBNetwork / python-decouple

Strict separation of config from code.
MIT License
2.82k stars 195 forks source link

Infinite recursion in _find_file on Windows when called via pytest #152

Closed mshafer1 closed 1 year ago

mshafer1 commented 1 year ago

Relevant info:

Debugging information: For some reason, when I run pytest on a module (A) that depends on a module (B) that pulls in decouple, self._caller_path() return "c:\Users\...", but if I import decouple in my test (in A) and call it directly, search_path comes in as "C:\Users\..."

The former of these causes an infinite recursion in _find_file since os.path.abspath(os.sep) returns C:\\.... (equivalent to Windows, but not to string comparisons...)

I could raise a PR to contribute either:

unfortunately, since python-decouple uses travis, I'm not sure adding a Windows run to the test suite will be easy, nor am I sure that would catch this case since I'm only seeing this when executing via python -m pytest...

mshafer1 commented 1 year ago

Hypothesis, somewhere pytest is calling os.path.normcase

henriquebastos commented 1 year ago

This looks like a bug. I am not sure how to reproduce because I do not have any access to Windows machines.

You can use a workaround for now:

from decouple import Config, RepositoryEnv
config = Config(RepositoryEnv("path-to-my-env-file"))
henriquebastos commented 1 year ago

Also if you provide a PR, I can gladly check it out.

mshafer1 commented 1 year ago

The workaround I've used for now is to create an empty .env file when I hit this.

PR #154 opened to fix.

henriquebastos commented 1 year ago

Fixed