Skip to content

Commit 0e48638

Browse files
committed
pytest-virtualenv: fix: Preserve python3.7 test behaviour while supporting all python versions
1 parent 706254e commit 0e48638

File tree

1 file changed

+12
-25
lines changed

1 file changed

+12
-25
lines changed

pytest-virtualenv/pytest_virtualenv.py

Lines changed: 12 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -210,11 +210,7 @@ def install_package(self, pkg_name, version=PackageVersion.LATEST, installer="pi
210210
installer += ' -q'
211211

212212
if version == PackageVersion.LATEST:
213-
self.run(
214-
"{python} {installer} {installer_command} {spec}".format(
215-
python=self.python, installer=installer, installer_command=installer_command, spec=pkg_name
216-
)
217-
)
213+
spec = pkg_name
218214
elif version == PackageVersion.CURRENT:
219215
dist = next(
220216
iter([dist for dist in distributions() if _normalize(dist.name) == _normalize(pkg_name)]), None
@@ -225,31 +221,22 @@ def install_package(self, pkg_name, version=PackageVersion.LATEST, installer="pi
225221
)
226222
egg_link = _get_egg_link(dist.name)
227223
if pkg_location:
228-
self.run(
229-
f"{self.python} {installer} {installer_command} -e {pkg_location}"
230-
)
224+
spec = f" -e {pkg_location}"
231225
elif egg_link:
232226
self._install_package_from_editable_egg_link(egg_link, dist)
227+
return
233228
else:
234-
spec = "{pkg_name}=={version}".format(pkg_name=pkg_name, version=dist.version)
235-
self.run(
236-
"{python} {installer} {installer_command} {spec}".format(
237-
python=self.python, installer=installer, installer_command=installer_command, spec=spec
238-
)
239-
)
229+
setup_files = ["pyproject.toml", "setup.py"]
230+
if any(os.path.exists(dist.locate_file(f)) for f in setup_files):
231+
spec = dist.locate_file("")
232+
else:
233+
spec = f"{pkg_name}=={dist.version}"
240234
else:
241-
self.run(
242-
"{python} {installer} {installer_command} {spec}".format(
243-
python=self.python, installer=installer, installer_command=installer_command, spec=pkg_name
244-
)
245-
)
235+
spec = pkg_name
246236
else:
247-
spec = "{pkg_name}=={version}".format(pkg_name=pkg_name, version=version)
248-
self.run(
249-
"{python} {installer} {installer_command} {spec}".format(
250-
python=self.python, installer=installer, installer_command=installer_command, spec=spec
251-
)
252-
)
237+
spec = f"{pkg_name}=={version}"
238+
cmd = f"{self.python} {installer} {installer_command} {spec}"
239+
self.run(cmd)
253240

254241
def installed_packages(self, package_type=None):
255242
"""

0 commit comments

Comments
 (0)