Commit bf331a54 by Sébastien Eustace Committed by GitHub

Speed up tests (#2257)

When testing the behavior for git packages with a setup.py file, the Provider class would create a temporary virtual environment and execute python setup.py egg_info. Both actions are costly and take time. By mocking them, we can reduce the tests time by a factor of 4 or 5.
parent 655f5825
...@@ -4,7 +4,6 @@ ...@@ -4,7 +4,6 @@
*.egg *.egg
!/tests/**/*.egg !/tests/**/*.egg
/*.egg-info /*.egg-info
/tests/fixtures/**/*.egg-info
/dist/* /dist/*
build build
_build _build
......
...@@ -326,10 +326,7 @@ class Provider: ...@@ -326,10 +326,7 @@ class Provider:
os.chdir(str(directory)) os.chdir(str(directory))
try: try:
with temporary_directory() as tmp_dir: cls._execute_setup()
EnvManager.build_venv(tmp_dir)
venv = VirtualEnv(Path(tmp_dir), Path(tmp_dir))
venv.run("python", "setup.py", "egg_info")
except EnvCommandError: except EnvCommandError:
result = SetupReader.read_from_directory(directory) result = SetupReader.read_from_directory(directory)
if not result["name"]: if not result["name"]:
...@@ -817,3 +814,9 @@ class Provider: ...@@ -817,3 +814,9 @@ class Provider:
yield yield
self._in_progress = False self._in_progress = False
def _execute_setup(self):
with temporary_directory() as tmp_dir:
EnvManager.build_venv(tmp_dir)
venv = VirtualEnv(Path(tmp_dir), Path(tmp_dir))
venv.run("python", "setup.py", "egg_info")
...@@ -116,3 +116,23 @@ known_third_party = [ ...@@ -116,3 +116,23 @@ known_third_party = [
"shellingham", "shellingham",
"tomlkit", "tomlkit",
] ]
[tool.black]
line-length = 88
include = '\.pyi?$'
exclude = '''
/(
\.eggs
| \.git
| \.hg
| \.mypy_cache
| \.tox
| \.venv
| _build
| buck-out
| build
| dist
| tests/.*/setup.py
)/
'''
...@@ -74,6 +74,11 @@ def download_mock(mocker): ...@@ -74,6 +74,11 @@ def download_mock(mocker):
mocker.patch("poetry.utils.inspector.Inspector.download", new=mock_download) mocker.patch("poetry.utils.inspector.Inspector.download", new=mock_download)
@pytest.fixture(autouse=True)
def execute_setup_mock(mocker):
mocker.patch("poetry.puzzle.provider.Provider._execute_setup")
@pytest.fixture @pytest.fixture
def environ(): def environ():
original_environ = dict(os.environ) original_environ = dict(os.environ)
......
Metadata-Version: 2.1
Name: demo
Version: 0.1.2
Summary: Demo project.
Home-page: https://github.com/demo/demo
Author: Sébastien Eustace
Author-email: sebastien@eustace.io
License: MIT
Description: UNKNOWN
Platform: UNKNOWN
Provides-Extra: bar
Provides-Extra: foo
setup.py
demo/__init__.py
demo.egg-info/PKG-INFO
demo.egg-info/SOURCES.txt
demo.egg-info/dependency_links.txt
demo.egg-info/requires.txt
demo.egg-info/top_level.txt
Metadata-Version: 1.0
Name: demo
Version: 0.1.2
Summary: Demo project.
Home-page: https://github.com/demo/demo
Author: Sébastien Eustace
Author-email: sebastien@eustace.io
License: MIT
Description: UNKNOWN
Platform: UNKNOWN
setup.py
demo/__init__.py
demo.egg-info/PKG-INFO
demo.egg-info/SOURCES.txt
demo.egg-info/dependency_links.txt
demo.egg-info/top_level.txt
Metadata-Version: 2.1
Name: Demo
Version: 0.1.2
Summary: Demo project.
Home-page: https://github.com/demo/demo
Author: Sébastien Eustace
Author-email: sebastien@eustace.io
License: MIT
Description: UNKNOWN
Platform: UNKNOWN
Provides-Extra: foo
Provides-Extra: bar
setup.py
Demo.egg-info/PKG-INFO
Demo.egg-info/SOURCES.txt
Demo.egg-info/dependency_links.txt
Demo.egg-info/requires.txt
Demo.egg-info/top_level.txt
demo/__init__.py
Metadata-Version: 1.0
Name: my-package
Version: 0.1.2
Summary: Demo project.
Home-page: https://github.com/demo/demo
Author: Sébastien Eustace
Author-email: sebastien@eustace.io
License: MIT
Description: UNKNOWN
Platform: UNKNOWN
setup.py
my_package/__init__.py
my_package.egg-info/PKG-INFO
my_package.egg-info/SOURCES.txt
my_package.egg-info/dependency_links.txt
my_package.egg-info/requires.txt
my_package.egg-info/top_level.txt
My Package My Package
========== ==========
\ No newline at end of file
...@@ -118,7 +118,7 @@ def test_search_for_vcs_read_setup_with_extras(provider, mocker): ...@@ -118,7 +118,7 @@ def test_search_for_vcs_read_setup_with_extras(provider, mocker):
def test_search_for_vcs_read_setup_raises_error_if_no_version(provider, mocker): def test_search_for_vcs_read_setup_raises_error_if_no_version(provider, mocker):
mocker.patch( mocker.patch(
"poetry.utils.env.VirtualEnv.run", "poetry.puzzle.provider.Provider._execute_setup",
side_effect=EnvCommandError(CalledProcessError(1, "python", output="")), side_effect=EnvCommandError(CalledProcessError(1, "python", output="")),
) )
......
...@@ -225,5 +225,3 @@ A full list of contributors can be found in `GitHub's overview <https://github.c ...@@ -225,5 +225,3 @@ A full list of contributors can be found in `GitHub's overview <https://github.c
It’s the spiritual successor of `characteristic <https://characteristic.readthedocs.io/>`_ and aspires to fix some of it clunkiness and unfortunate decisions. It’s the spiritual successor of `characteristic <https://characteristic.readthedocs.io/>`_ and aspires to fix some of it clunkiness and unfortunate decisions.
Both were inspired by Twisted’s `FancyEqMixin <https://twistedmatrix.com/documents/current/api/twisted.python.util.FancyEqMixin.html>`_ but both are implemented using class decorators because `subclassing is bad for you <https://www.youtube.com/watch?v=3MNVP9-hglc>`_, m’kay? Both were inspired by Twisted’s `FancyEqMixin <https://twistedmatrix.com/documents/current/api/twisted.python.util.FancyEqMixin.html>`_ but both are implemented using class decorators because `subclassing is bad for you <https://www.youtube.com/watch?v=3MNVP9-hglc>`_, m’kay?
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