From 980d04bc5a0c4d97222d503a89103c97f140b737 Mon Sep 17 00:00:00 2001 From: Carl George Date: Thu, 29 Aug 2024 21:49:56 -0500 Subject: [PATCH] tests: optional uv Skip the tests that need uv when uv is not installed. This makes it easier for Linux distros that package build to avoid a build-time dependency on uv. Update tests/test_env.py --- tests/test_env.py | 20 ++++++++++++++++---- tests/test_integration.py | 10 +++++++++- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/tests/test_env.py b/tests/test_env.py index 6eaa0234..1fcd6855 100644 --- a/tests/test_env.py +++ b/tests/test_env.py @@ -21,6 +21,7 @@ IS_PYPY = sys.implementation.name == 'pypy' IS_WINDOWS = sys.platform.startswith('win') +MISSING_UV = not shutil.which('uv') @pytest.mark.isolated @@ -206,6 +207,7 @@ def test_default_impl_install_cmd_well_formed( @pytest.mark.parametrize('verbosity', range(4)) @pytest.mark.skipif(IS_PYPY, reason='uv cannot find PyPy executable') +@pytest.mark.skipif(MISSING_UV, reason='uv executable not found') def test_uv_impl_install_cmd_well_formed( mocker: pytest_mock.MockerFixture, verbosity: int, @@ -237,7 +239,12 @@ def test_uv_impl_install_cmd_well_formed( ('pip', 'venv+pip', False), ('pip', 'virtualenv+pip', True), ('pip', 'virtualenv+pip', None), # Fall-through - ('uv', 'venv+uv', None), + pytest.param( + 'uv', + 'venv+uv', + None, + marks=pytest.mark.skipif(MISSING_UV, reason='uv executable not found'), + ), ], indirect=('has_virtualenv',), ) @@ -257,9 +264,13 @@ def test_venv_creation( 'pip', pytest.param( 'uv', - marks=pytest.mark.xfail( - IS_PYPY and IS_WINDOWS and sys.version_info < (3, 9), reason='uv cannot find PyPy 3.8 executable on Windows' - ), + marks=[ + pytest.mark.xfail( + IS_PYPY and IS_WINDOWS and sys.version_info < (3, 9), + reason='uv cannot find PyPy 3.8 executable on Windows', + ), + pytest.mark.skipif(MISSING_UV, reason='uv executable not found'), + ], ), ], ) @@ -271,6 +282,7 @@ def test_requirement_installation( env.install([f'test-flit @ {Path(package_test_flit).as_uri()}']) +@pytest.mark.skipif(MISSING_UV, reason='uv executable not found') def test_external_uv_detection_success( caplog: pytest.LogCaptureFixture, mocker: pytest_mock.MockerFixture, diff --git a/tests/test_integration.py b/tests/test_integration.py index 99dae5c8..541e140e 100644 --- a/tests/test_integration.py +++ b/tests/test_integration.py @@ -18,6 +18,7 @@ IS_WINDOWS = sys.platform.startswith('win') IS_PYPY = sys.implementation.name == 'pypy' +MISSING_UV = not shutil.which('uv') INTEGRATION_SOURCES = { @@ -79,7 +80,14 @@ def _ignore_folder(base, filenames): ) @pytest.mark.parametrize( 'args', - [[], ['--installer', 'uv'], ['-x', '--no-isolation']], + [ + [], + pytest.param( + ['--installer', 'uv'], + marks=pytest.mark.skipif(MISSING_UV, reason='uv executable not found'), + ), + ['-x', '--no-isolation'], + ], ids=['isolated_pip', 'isolated_uv', 'no_isolation'], ) @pytest.mark.parametrize(