Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
python-poetry
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
open
python-poetry
Commits
4387523e
Commit
4387523e
authored
May 11, 2022
by
Arun Babu Neelicattu
Committed by
Bjorn Neergaard
May 10, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
tests: isolate python env vars
parent
d6070201
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
11 deletions
+24
-11
tests/conftest.py
+4
-11
tests/helpers.py
+20
-0
No files found.
tests/conftest.py
View file @
4387523e
...
...
@@ -34,6 +34,7 @@ from poetry.utils.helpers import remove_directory
from
tests.helpers
import
TestLocker
from
tests.helpers
import
TestRepository
from
tests.helpers
import
get_package
from
tests.helpers
import
isolated_environment
from
tests.helpers
import
mock_clone
from
tests.helpers
import
mock_download
...
...
@@ -246,28 +247,20 @@ def pep517_metadata_mock(mocker: MockerFixture) -> None:
@pytest.fixture
def
environ
()
->
Iterator
[
None
]:
original_environ
=
dict
(
os
.
environ
)
with
isolated_environment
():
yield
os
.
environ
.
clear
()
os
.
environ
.
update
(
original_environ
)
@pytest.fixture
(
autouse
=
True
)
def
isolate_environ
()
->
Iterator
[
None
]:
"""Ensure the environment is isolated from user configuration."""
original_environ
=
dict
(
os
.
environ
)
with
isolated_environment
():
for
var
in
os
.
environ
:
if
var
.
startswith
(
"POETRY_"
)
:
if
var
.
startswith
(
"POETRY_"
)
or
var
in
{
"PYTHONPATH"
,
"VIRTUAL_ENV"
}
:
del
os
.
environ
[
var
]
yield
os
.
environ
.
clear
()
os
.
environ
.
update
(
original_environ
)
@pytest.fixture
(
autouse
=
True
)
def
git_mock
(
mocker
:
MockerFixture
)
->
None
:
...
...
tests/helpers.py
View file @
4387523e
from
__future__
import
annotations
import
contextlib
import
os
import
re
import
shutil
...
...
@@ -9,6 +10,7 @@ import urllib.parse
from
pathlib
import
Path
from
typing
import
TYPE_CHECKING
from
typing
import
Any
from
typing
import
Iterator
from
poetry.core.masonry.utils.helpers
import
escape_name
from
poetry.core.masonry.utils.helpers
import
escape_version
...
...
@@ -230,3 +232,21 @@ class TestRepository(Repository):
f
"-{escape_version(package.version.text)}-py2.py3-none-any.whl"
)
]
@contextlib.contextmanager
def
isolated_environment
(
environ
:
dict
[
str
,
Any
]
|
None
=
None
,
clear
:
bool
=
False
)
->
Iterator
[
None
]:
original_environ
=
dict
(
os
.
environ
)
if
clear
:
os
.
environ
.
clear
()
if
environ
:
os
.
environ
.
update
(
environ
)
yield
os
.
environ
.
clear
()
os
.
environ
.
update
(
original_environ
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment