I'm trying to figure out why my pytest script in a virtualenv has the wrong shebang path.
I'm on MacOS using pyenv and virtualenv.
$ pyenv which python
/Users/me/.pyenv/versions/screenpy_examples/bin/python
$ pyenv which pytest
/Users/me/.pyenv/versions/screenpy_examples/bin/pytest
$ cat /Users/me/.pyenv/versions/screenpy_examples/bin/pytest | head -n 1
#!/Users/me/.pyenv/versions/3.11.2/envs/screenpy_examples/bin/python3.11
The problem
Is when pytest
runs on commandline it calls python using the realpath whereas when I use python -m pytest
it's calling python using the symlink. The module paths stored in __pycache__
are different depending on which way you call python. I have a custom logger that depends on those file paths to filter out modules when logging filename and line numbers which of course breaks unless the cache has been cleared or I set PYTHONDONTWRITEBYTECODE=1
and I happen to run the test suite say from commandline after having run it in pycharm.
What to do about it?
I'd like to figure out what sets that shebang in my installed pytest
script. My current hunch is there is a bug somewhere during install, but it's unclear to me who to report this to (virtualenv, pip, pytest). What part of the install package sets that shebang?
My best hope would be it's simply a matter of configuring the environment differently before installing pytest so it gets the proper shebang.