Commit 7b13f003 by Darren Weber Committed by Bryce Drennan

Optimize tests/conftest.py (#1271)

- apply the PyCharm "optimize imports"
- place functions above fixtures
- alphabetize fixture functions
- remove duplicate tmp_dir fixture
parent 7b1e01f3
import httpretty
import os import os
import pytest
import shutil import shutil
import tempfile import tempfile
import httpretty
import pytest
try: try:
import urllib.parse as urlparse import urllib.parse as urlparse
except ImportError: except ImportError:
...@@ -20,15 +21,6 @@ from poetry.utils.toml_file import TomlFile ...@@ -20,15 +21,6 @@ from poetry.utils.toml_file import TomlFile
@pytest.fixture @pytest.fixture
def tmp_dir():
dir_ = tempfile.mkdtemp(prefix="poetry_")
yield dir_
shutil.rmtree(dir_)
@pytest.fixture
def config_document(): def config_document():
content = """cache-dir = "/foo" content = """cache-dir = "/foo"
""" """
...@@ -101,13 +93,10 @@ def mock_download(self, url, dest): ...@@ -101,13 +93,10 @@ def mock_download(self, url, dest):
os.symlink(str(fixture), str(dest)) os.symlink(str(fixture), str(dest))
@pytest.fixture @pytest.fixture(autouse=True)
def tmp_dir(): def download_mock(mocker):
dir_ = tempfile.mkdtemp(prefix="poetry_") # Patch download to not download anything but to just copy from fixtures
mocker.patch("poetry.utils.inspector.Inspector.download", new=mock_download)
yield dir_
shutil.rmtree(dir_)
@pytest.fixture @pytest.fixture
...@@ -129,12 +118,6 @@ def git_mock(mocker): ...@@ -129,12 +118,6 @@ def git_mock(mocker):
p.return_value = "9cf87a285a2d3fbb0b9fa621997b3acc3631ed24" p.return_value = "9cf87a285a2d3fbb0b9fa621997b3acc3631ed24"
@pytest.fixture(autouse=True)
def download_mock(mocker):
# Patch download to not download anything but to just copy from fixtures
mocker.patch("poetry.utils.inspector.Inspector.download", new=mock_download)
@pytest.fixture @pytest.fixture
def http(): def http():
httpretty.enable() httpretty.enable()
...@@ -150,3 +133,12 @@ def fixture_dir(): ...@@ -150,3 +133,12 @@ def fixture_dir():
return Path(__file__).parent / "fixtures" / name return Path(__file__).parent / "fixtures" / name
return _fixture_dir return _fixture_dir
@pytest.fixture
def tmp_dir():
dir_ = tempfile.mkdtemp(prefix="poetry_")
yield dir_
shutil.rmtree(dir_)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment