Skip to content

Commit 1b12358

Browse files
radoeringneersighted
authored andcommitted
fix(tests): make tests independent of cwd
1 parent efcfd34 commit 1b12358

File tree

1 file changed

+15
-20
lines changed

1 file changed

+15
-20
lines changed

tests/test_exporter.py

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
from __future__ import annotations
22

3-
from pathlib import Path
43
from typing import TYPE_CHECKING
54
from typing import Any
65

@@ -36,15 +35,17 @@
3635

3736

3837
if TYPE_CHECKING:
38+
from pathlib import Path
39+
3940
from packaging.utils import NormalizedName
4041
from poetry.poetry import Poetry
4142

4243
from tests.conftest import Config
4344

4445

4546
class Locker(BaseLocker):
46-
def __init__(self) -> None:
47-
self._lock = TOMLFile(Path.cwd().joinpath("poetry.lock"))
47+
def __init__(self, fixture_root: Path) -> None:
48+
self._lock = TOMLFile(fixture_root / "poetry.lock")
4849
self._locked = True
4950
self._content_hash = self._get_content_hash()
5051

@@ -66,9 +67,9 @@ def _get_content_hash(self) -> str:
6667
return "123456789"
6768

6869

69-
@pytest.fixture()
70-
def locker() -> Locker:
71-
return Locker()
70+
@pytest.fixture
71+
def locker(fixture_root: Path) -> Locker:
72+
return Locker(fixture_root)
7273

7374

7475
@pytest.fixture
@@ -1260,7 +1261,7 @@ def test_exporter_can_export_requirements_txt_with_directory_packages(
12601261
"python-versions": "*",
12611262
"source": {
12621263
"type": "directory",
1263-
"url": "tests/fixtures/sample_project",
1264+
"url": "sample_project",
12641265
"reference": "",
12651266
},
12661267
}
@@ -1301,7 +1302,7 @@ def test_exporter_can_export_requirements_txt_with_nested_directory_packages(
13011302
"python-versions": "*",
13021303
"source": {
13031304
"type": "directory",
1304-
"url": "tests/fixtures/sample_project",
1305+
"url": "sample_project",
13051306
"reference": "",
13061307
},
13071308
},
@@ -1313,10 +1314,7 @@ def test_exporter_can_export_requirements_txt_with_nested_directory_packages(
13131314
"python-versions": "*",
13141315
"source": {
13151316
"type": "directory",
1316-
"url": (
1317-
"tests/fixtures/sample_project/"
1318-
"../project_with_nested_local/bar"
1319-
),
1317+
"url": "sample_project/../project_with_nested_local/bar",
13201318
"reference": "",
13211319
},
13221320
},
@@ -1328,10 +1326,7 @@ def test_exporter_can_export_requirements_txt_with_nested_directory_packages(
13281326
"python-versions": "*",
13291327
"source": {
13301328
"type": "directory",
1331-
"url": (
1332-
"tests/fixtures/sample_project/"
1333-
"../project_with_nested_local/bar/.."
1334-
),
1329+
"url": "sample_project/../project_with_nested_local/bar/..",
13351330
"reference": "",
13361331
},
13371332
},
@@ -1375,7 +1370,7 @@ def test_exporter_can_export_requirements_txt_with_directory_packages_and_marker
13751370
"marker": "python_version < '3.7'",
13761371
"source": {
13771372
"type": "directory",
1378-
"url": "tests/fixtures/sample_project",
1373+
"url": "sample_project",
13791374
"reference": "",
13801375
},
13811376
}
@@ -1417,7 +1412,7 @@ def test_exporter_can_export_requirements_txt_with_file_packages(
14171412
"python-versions": "*",
14181413
"source": {
14191414
"type": "file",
1420-
"url": "tests/fixtures/distributions/demo-0.1.0.tar.gz",
1415+
"url": "distributions/demo-0.1.0.tar.gz",
14211416
"reference": "",
14221417
},
14231418
}
@@ -1460,7 +1455,7 @@ def test_exporter_can_export_requirements_txt_with_file_packages_and_markers(
14601455
"marker": "python_version < '3.7'",
14611456
"source": {
14621457
"type": "file",
1463-
"url": "tests/fixtures/distributions/demo-0.1.0.tar.gz",
1458+
"url": "distributions/demo-0.1.0.tar.gz",
14641459
"reference": "",
14651460
},
14661461
}
@@ -2573,7 +2568,7 @@ def test_exporter_raises_exception_for_constraints_txt_with_editable_packages(
25732568
"python-versions": "*",
25742569
"source": {
25752570
"type": "directory",
2576-
"url": "tests/fixtures/sample_project",
2571+
"url": "sample_project",
25772572
"reference": "",
25782573
},
25792574
"develop": True,

0 commit comments

Comments
 (0)