Skip to content

Commit 95ca8ab

Browse files
committed
pytest-virtualenv: fix: Install local dir to virtualenv in later py3
Preserve python3.7 test behaviour while supporting all python versions
1 parent 83aaeb1 commit 95ca8ab

File tree

2 files changed

+15
-26
lines changed

2 files changed

+15
-26
lines changed

CHANGES.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
## Changelog
1+
# Changelog
22

33
### 1.9.0
4+
45
* All: Update `make test` runner to use `pytest` instead of deprecated `setup.py test`
56
* pytest-server-fixtures: Update deprecated mongo 7.* to 8.2
67
* pytest-profile: add support for `cProfile` regex to filter output
78
* pytest-profile: update README.md args
9+
* pytest-virtualenv: fix: Install local dir to virtualenv in later py3
810
* ci: fix py3.7-3.13 ubuntu
911
* ci: Update support in tests for py3.7-13 for ubuntu 22.04
1012

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)