Skip to content

Commit

Permalink
Remove custom implementation of _venv_get_version_or_none
Browse files Browse the repository at this point in the history
  • Loading branch information
frenzymadness committed Nov 28, 2023
1 parent e9b65bf commit fac256e
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 17 deletions.
14 changes: 0 additions & 14 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

import pytest
import os
import subprocess
from tempfile import TemporaryDirectory

try:
Expand Down Expand Up @@ -53,18 +52,6 @@ def _venv_install_pip(venv):
venv.install(f"setuptools{MICROPIPENV_TEST_SETUPTOOLS_VERSION}")


def _venv_get_version_or_none(self, package):
"""Extend the original method from pytest-venv fixture.
See https://github.com/mmerickel/pytest-venv/issues/3
"""
try:
version = self.get_version(package)
return version
except subprocess.CalledProcessError:
return None


def pytest_configure(config):
"""Configure tests before pytest collects tests."""
global PIP_VERSION
Expand Down Expand Up @@ -94,7 +81,6 @@ def venv_with_pip():

with TemporaryDirectory() as tmp_dir:
# Extend the VirtulEnvironment class first
VirtualEnvironment.get_version_or_none = _venv_get_version_or_none
venv = VirtualEnvironment(str(tmp_dir))
venv.create()
_venv_install_pip(venv)
Expand Down
6 changes: 3 additions & 3 deletions tests/test_micropipenv.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,11 +308,11 @@ def test_install_poetry_complex_example(venv):
subprocess.run(cmd, check=True, env=get_updated_env(venv))
assert str(venv.get_version("requests")) == "2.27.1"
# Dependency defined as requests[use_chardet_on_py3] extra
assert venv.get_version_or_none("chardet") is not None
assert venv.get_version("chardet", raises=False) is not None
# unicodedata2 is provided as charset-normalizer[unicode_backport] but is not specified for installation
assert venv.get_version_or_none("unicodedata2") is None
assert venv.get_version("unicodedata2", raises=False) is None
# also, requests[socks] or urllib3[socks] should not be installed
assert venv.get_version_or_none("PySocks") is None
assert venv.get_version("PySocks", raises=False) is None


@pytest.mark.online
Expand Down

0 comments on commit fac256e

Please sign in to comment.