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

fix(windows): running tests in a virtual environment (alt 2) #2216

Merged
merged 4 commits into from Mar 27, 2023

Conversation

mayeut
Copy link
Contributor

@mayeut mayeut commented Mar 25, 2023

Summary

Description

On windows, starting with python 3.7,
virtual environments use a venvlauncher startup process This does not play well when counting spawned processes or when relying on the pid of the spawned process to do some checks e.g. connection check per pid

This commit detects this situation and uses the base python executable to spawn processes when required.

2nd alternative to #2209, exposes PYTHON_EXE_ENV to be set as the base environment when starting a process using PYTHON_EXE.

The 1st commit always uses env= PYTHON_EXE_ENV.
The 2nd commit removes occurrences when calling psutil.tests.spawn_testproc (either directly or indirectly) which uses this as its default environment.

On windows, starting with python 3.7,
virtual environments use a venvlauncher startup process
This does not play well when counting spawned processes or
when relying on the pid of the spawned process to do some checks
e.g. connection check per pid

This commit detects this situation and uses the base python
executable to spawn processes when required.

Signed-off-by: mayeut <mayeut@users.noreply.github.com>
Signed-off-by: mayeut <mayeut@users.noreply.github.com>
Copy link
Owner

@giampaolo giampaolo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is the cleanest approach. I just added a couple of minor comments.

psutil/tests/__init__.py Outdated Show resolved Hide resolved
psutil/tests/__init__.py Outdated Show resolved Hide resolved
Signed-off-by: mayeut <mayeut@users.noreply.github.com>
@giampaolo giampaolo merged commit 64b4318 into giampaolo:master Mar 27, 2023
9 of 12 checks passed
@giampaolo
Copy link
Owner

Merged. Thank you Matthew.

giampaolo added a commit that referenced this pull request Mar 27, 2023
@mayeut mayeut deleted the win-venv-tests-env branch March 27, 2023 22:03
ddelange added a commit to ddelange/psutil that referenced this pull request Mar 29, 2023
* 'master' of https://github.com/giampaolo/psutil:
  [Linux] guess `available` virtual_memory() if kernel says it's 0 (giampaolo#2052)
  fix C compilation warning on Linux + Python 2
  fix linux tests
  update HISTORY
  update HISTORY/CREDITS for giampaolo#2216 / @mayeut
  When raising warning, always use stacklevel=2
  Win: fix running tests in a virtual environment (giampaolo#2216)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants