Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unittest: sys.path is different when running from terminal vs test UI #23239

Open
karthiknadig opened this issue Apr 15, 2024 · 11 comments
Open
Assignees
Labels
area-testing bug Issue identified by VS Code Team member as probable bug

Comments

@karthiknadig
Copy link
Member

CWD looks the same. syspath is very different.

From vscode:

['helios', '/home/juledwar/.vscode/extensions/ms-python.python-2024.0.1/pythonFiles/lib/python', '/home/juledwar/.vscode/extensions/ms-python.python-2024.0.1/pythonFiles/unittestadapter', '/home/juledwar/src/helios/.hatch/lib/python3.12/site-packages/_pdbpp_path_hack', '/home/juledwar/src/helios', '/usr/lib/python312.zip', '/usr/lib/python3.12', '/usr/lib/python3.12/lib-dynload', '/home/juledwar/src/helios/.hatch/lib/python3.12/site-packages', '/home/juledwar/.vscode/extensions/ms-python.python-2024.0.1/pythonFiles', '/home/juledwar/.vscode/extensions/ms-python.python-2024.0.1/pythonFiles', '/home/juledwar/.vscode/extensions/ms-python.python-2024.0.1/pythonFiles/lib/python']
/home/juledwar/src/helios

From the CLI

['/home/juledwar/src/helios', '/home/juledwar/src/helios/.hatch/lib/python3.12/site-packages/_pdbpp_path_hack', '/usr/lib/python312.zip', '/usr/lib/python3.12', '/usr/lib/python3.12/lib-dynload', '/home/juledwar/src/helios/.hatch/lib/python3.12/site-packages', '/home/juledwar/src/helios']
/home/juledwar/src/helios

Originally posted by @bigjools in #17641 (comment)

@eleanorjboyd
Copy link
Member

saw your comment- is it worth trying to figure this out now or wait until we remove the experiment which is currently 1 issue away?

@github-actions github-actions bot added the info-needed Issue requires more information from poster label Apr 22, 2024
@karthiknadig
Copy link
Member Author

I think we can ship the plugin. This can be addressed after, I think this might actually turnout to be activated run bug.

@github-actions github-actions bot removed the info-needed Issue requires more information from poster label Apr 22, 2024
@bigjools
Copy link

bigjools commented May 2, 2024

Incredibly, this is now fixed on the latest pre-release I installed just now. Did you change something?

@inoa-dmpassy
Copy link

A test fails due to this:

output = subprocess.run("pyrsa-sign", capture_output=True, text=True, encoding="utf-8", shell=True)
# pyrsa-sign' is not recognized as an internal or external command

pyrsa-sign sits at env/Scripts/pyrsa-sign.exe (windows machine), however, due to the test runner not appending env (both sites packages and Scripts) to the PATH, it fails to identify this executable.

Currently using extensions "Python v2024.6.0"

well, I'll just mock this for now, but I can see this being a problem

@eleanorjboyd
Copy link
Member

Hi @inoa-dmpassy! Could you include your full test? Are you running the subprocess inside your given test?

Secondly, what do you mean by not appending env? Are you saying env from you computer or from your specific environment? We should be finding the environment, appending so if you are not seeing a variable you expect then that is a different problem.

Thanks

@github-actions github-actions bot added the info-needed Issue requires more information from poster label May 6, 2024
@eleanorjboyd
Copy link
Member

Incredibly, this is now fixed on the latest pre-release I installed just now. Did you change something?

We have changed some stuff but nothing which I thought changed path- I will look to see if I can also repro the fix

@inoa-dmpassy
Copy link

inoa-dmpassy commented May 6, 2024

@eleanorjboyd , yes, I'm running subprocess inside the test, these are the important lines:

command = [
    "pyrsa-sign",
    os.path.join(PROJ_DIR, "build_private.key"),
    "SHA-512",
    "--input=" + str(self.inner_zip),
    "--output=" + str(self.work_dir / "alphatools_update_package.sig"),
]
output = subprocess.run(cmd, capture_output=True, text=True, encoding="utf-8", shell=True)        

here's the tree comand of my currenct active command:

danielpass@DESKTOP-HLLM1EK:/mnt/c/Users/DMpassy/Projects/alphatools-main$ tree -L 2 env/
env/
├── CACHEDIR.TAG
├── CMakeLists.txt
├── COPYING
├── HISTORY.md
├── Lib
│   └── site-packages
├── README.md
├── Scripts
│   ├── activate
│   ├──# (a bunch of stuff)
│   ├── pyrsa-decrypt.exe
│   ├── pyrsa-encrypt.exe
│   ├── pyrsa-keygen.exe
│   ├── pyrsa-priv2pub.exe
│   ├── pyrsa-sign.exe
│   ├── pyrsa-verify.exe
│   ├── pystache-test.exe
│   ├── pystache.exe
│   ├── pytest.exe
│   ├── python.exe
│   ├──# (even more stuff)
├── extern
│   └── rapidfuzz-cpp
├── include
│   ├── Hamming.hpp
│   ├──# (a bunch of stuff)
├── man
│   └── man1
├── pyproject.toml
├── pyvenv.cfg
├── setup.py
├── share
│   └── man
└── src
    └── cython

if I run it in debug mode using vscode test runner, it works.
If I run in normal mode, it priunts an error "pyrsa-sign is not a valid command"
On the first case, (...)/env/Scripts is in the Path variable; not in the second one;

@eleanorjboyd
Copy link
Member

great info thank you! Sounds like you found the item in the path that is not being added correctly. How do you expect the Scripts path to be added to the python path?What is the setup of yourproject? Just like the tree? Just want to clarify since I am unsure where you are running things from and how that would then impact the python path and why we are missing that specific path for you.

@inoa-dmpassy
Copy link

inoa-dmpassy commented May 7, 2024

I'm running on windows

This is my project setup

project_dir
- main/
-- tests/
---test_example.py
- env/
- manage.py (django project)
- (...)

Using ctrl + P -> Python: Select interpreter, it indicates that the env/ python is selected.
This, in my understanding, would be a global option, every interaction is vscode would appropriately activate this env.

What I mean by activating the env is calling source env/bin/activate (linux), env/Script/activate (windows). This scripts does many things.

Python docs relate to it,

A virtual environment may be “activated” using a script in its binary directory (bin on POSIX; Scripts on Windows). This will prepend that directory to your PATH, so that running python will invoke the environment’s Python interpreter and you can run installed scripts without having to use their full path.

I'd expect that the test runner would conform to the Python: Select interpreter settings and activate the env before running.

@eleanorjboyd
Copy link
Member

@karthiknadig, thoughts here on why testing many not be waiting for environment activation?

Copy link

github-actions bot commented Jun 7, 2024

Because we have not heard back with the information we requested, we are closing this issue for now. If you are able to provide the info later on, then we will be happy to re-open this issue to pick up where we left off.

Happy Coding!

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Jun 7, 2024
@eleanorjboyd eleanorjboyd reopened this Jun 7, 2024
@eleanorjboyd eleanorjboyd removed the info-needed Issue requires more information from poster label Jun 7, 2024
@eleanorjboyd eleanorjboyd removed the triage-needed Needs assignment to the proper sub-team label Dec 16, 2024
@karthiknadig karthiknadig added the bug Issue identified by VS Code Team member as probable bug label Dec 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-testing bug Issue identified by VS Code Team member as probable bug
Projects
None yet
Development

No branches or pull requests

4 participants