PATH env is not set to the virtualenv
Description
Some test code expects to be able to run a binary that's part of the test deps. I'm a little surprised that when running the $VENV/bin/python that $PATH is not updated to include $VENV/bin as you would get when activating a venv.
I can't think of an easy/universal way to do this from my test code (it would involve platform-sniffing at the very least).
See https://github.com/thatch/thx-repro-path for an example of how this might be used. This test passes only if you already have a pip on the path before running thx.
There are other things you might want to do with the path, but at a minimum I'm interested in adding the thx-managed venv bin. How would you feel about a PR that does this, perhaps hidden behind a new config option?
Details
- OS: Mac (but it shouldn't matter)
- Python version: 3.9, but it shouldn't matter
- thx version: 0.5.1
- Can you repro on main? probably
- Can you repro in a clean virtualenv? yes
I'm also wondering if this (setting $PATH) would be surprising; if the intent is to behave as a non-activated venv where you might advise using {sys.executable} -m pip and this is just a strange case I have where a test assumes that which() works.
Was easier to repro with something other than pip, because I never don't have pip on $PATH thanks to pyenv.
amethyst@glaceon ~/workspace/thx-repro main+ » git di
diff --git a/requirements.txt b/requirements.txt
index a1b589e..f06ef0e 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -1 +1,3 @@
pip
+attribution
+pytest
diff --git a/test_deps_installed.py b/test_deps_installed.py
index 0c6334a..3d6ceba 100644
--- a/test_deps_installed.py
+++ b/test_deps_installed.py
@@ -8,3 +8,5 @@ class DepsTest(unittest.TestCase):
print(sys.executable)
print(os.getenv("PATH"))
self.assertTrue(shutil.which("pip"))
+ self.assertTrue(shutil.which("attribution"))
+ self.assertTrue(shutil.which("pytest"))