Skip to content

Commit

Permalink
Improve markers for tests that should be skipped (#1532)
Browse files Browse the repository at this point in the history
  • Loading branch information
ofek authored May 26, 2024
1 parent 9982d03 commit 58d942d
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 2 deletions.
2 changes: 2 additions & 0 deletions tests/backend/builders/test_binary.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
from hatchling.builders.binary import BinaryBuilder
from hatchling.builders.plugin.interface import BuilderInterface

pytestmark = [pytest.mark.requires_cargo, pytest.mark.requires_internet]


class ExpectedEnvVars:
def __init__(self, env_vars: dict):
Expand Down
7 changes: 6 additions & 1 deletion tests/cli/publish/test_publish.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@

from hatch.config.constants import PublishEnvVars

pytestmark = [pytest.mark.usefixtures('devpi'), pytest.mark.usefixtures('local_backend_process')]
pytestmark = [
pytest.mark.requires_docker,
pytest.mark.requires_internet,
pytest.mark.usefixtures('devpi'),
pytest.mark.usefixtures('local_backend_process'),
]


@pytest.fixture(autouse=True)
Expand Down
38 changes: 37 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -458,9 +458,15 @@ def pytest_runtest_setup(item):
if marker.name == 'requires_unix' and PLATFORM.windows:
pytest.skip('Not running on a Linux-based platform')

if marker.name == 'requires_git' and not shutil.which('git'): # no cov
if marker.name == 'requires_git' and not git_available(): # no cov
pytest.skip('Git not present in the environment')

if marker.name == 'requires_docker' and not docker_available(): # no cov
pytest.skip('Docker not present in the environment')

if marker.name == 'requires_cargo' and not cargo_available(): # no cov
pytest.skip('Cargo not present in the environment')


def pytest_configure(config):
config.addinivalue_line('markers', 'requires_windows: Tests intended for Windows operating systems')
Expand All @@ -469,6 +475,12 @@ def pytest_configure(config):
config.addinivalue_line('markers', 'requires_unix: Tests intended for Linux-based operating systems')
config.addinivalue_line('markers', 'requires_internet: Tests that require access to the internet')
config.addinivalue_line('markers', 'requires_git: Tests that require the git command available in the environment')
config.addinivalue_line(
'markers', 'requires_docker: Tests that require the docker command available in the environment'
)
config.addinivalue_line(
'markers', 'requires_cargo: Tests that require the cargo command available in the environment'
)

config.addinivalue_line('markers', 'allow_backend_process: Force the use of backend communication')

Expand All @@ -491,3 +503,27 @@ def network_connectivity(): # no cov
return True

return False


@lru_cache
def git_available(): # no cov
if running_in_ci():
return True

return shutil.which('git') is not None


@lru_cache
def docker_available(): # no cov
if running_in_ci():
return True

return shutil.which('docker') is not None


@lru_cache
def cargo_available(): # no cov
if running_in_ci():
return True

return shutil.which('cargo') is not None

0 comments on commit 58d942d

Please sign in to comment.