-
Notifications
You must be signed in to change notification settings - Fork 654
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow use without virtualenv activation
Fixes: #1507
- Loading branch information
Showing
2 changed files
with
58 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
"""Tests related to ansiblelint.__main__ module.""" | ||
import os | ||
import subprocess | ||
import sys | ||
from pathlib import Path | ||
|
||
import pytest | ||
|
||
|
||
@pytest.mark.parametrize( | ||
("expected_warning"), | ||
(False, True), | ||
ids=("normal", "isolated"), | ||
) | ||
def test_call_from_outside_venv(expected_warning: bool) -> None: | ||
"""Asserts ability to be called w/ or w/o venv activation.""" | ||
env = None | ||
if expected_warning: | ||
env = {"HOME": Path.home()} | ||
py_path = os.path.dirname(sys.executable) | ||
# Passing custom env prevents the process from inheriting PATH or other | ||
# environment variables from the current process, so we emulate being | ||
# called from outside the venv. | ||
proc = subprocess.run( | ||
[f"{py_path}/ansible-lint", "--version"], | ||
check=True, | ||
stdout=subprocess.PIPE, | ||
stderr=subprocess.PIPE, | ||
universal_newlines=True, | ||
env=env, | ||
) | ||
warning_found = "PATH altered to include" in proc.stderr | ||
assert warning_found is expected_warning |