Skip to content

Commit

Permalink
refactor(test): use more uniform version-checking skips
Browse files Browse the repository at this point in the history
  • Loading branch information
nedbat committed Dec 19, 2023
1 parent dafebf1 commit 962429c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
2 changes: 2 additions & 0 deletions coverage/env.py
Expand Up @@ -29,6 +29,8 @@

# Python versions. We amend version_info with one more value, a zero if an
# official version, or 1 if built from source beyond an official version.
# Only use sys.version_info directly where tools like mypy need it to understand
# version-specfic code, otherwise use PYVERSION.
PYVERSION = sys.version_info + (int(platform.python_version()[-1] == "+"),)

if PYPY:
Expand Down
11 changes: 5 additions & 6 deletions tests/test_config.py
Expand Up @@ -5,13 +5,12 @@

from __future__ import annotations

import sys
from unittest import mock

import pytest

import coverage
from coverage import Coverage
from coverage import Coverage, env
from coverage.config import HandyConfigParser
from coverage.exceptions import ConfigError, CoverageWarning
from coverage.tomlconfig import TomlConfigParser
Expand Down Expand Up @@ -738,7 +737,7 @@ def test_no_toml_installed_no_toml(self) -> None:
with pytest.raises(ConfigError, match=msg):
coverage.Coverage(config_file="cov.toml")

@pytest.mark.skipif(sys.version_info >= (3, 11), reason="Python 3.11 has toml in stdlib")
@pytest.mark.skipif(env.PYVERSION >= (3, 11), reason="Python 3.11 has toml in stdlib")
def test_no_toml_installed_explicit_toml(self) -> None:
# Can't specify a toml config file if toml isn't installed.
self.make_file("cov.toml", "# A toml file!")
Expand All @@ -747,7 +746,7 @@ def test_no_toml_installed_explicit_toml(self) -> None:
with pytest.raises(ConfigError, match=msg):
coverage.Coverage(config_file="cov.toml")

@pytest.mark.skipif(sys.version_info >= (3, 11), reason="Python 3.11 has toml in stdlib")
@pytest.mark.skipif(env.PYVERSION >= (3, 11), reason="Python 3.11 has toml in stdlib")
def test_no_toml_installed_pyproject_toml(self) -> None:
# Can't have coverage config in pyproject.toml without toml installed.
self.make_file("pyproject.toml", """\
Expand All @@ -760,7 +759,7 @@ def test_no_toml_installed_pyproject_toml(self) -> None:
with pytest.raises(ConfigError, match=msg):
coverage.Coverage()

@pytest.mark.skipif(sys.version_info >= (3, 11), reason="Python 3.11 has toml in stdlib")
@pytest.mark.skipif(env.PYVERSION >= (3, 11), reason="Python 3.11 has toml in stdlib")
def test_no_toml_installed_pyproject_toml_shorter_syntax(self) -> None:
# Can't have coverage config in pyproject.toml without toml installed.
self.make_file("pyproject.toml", """\
Expand All @@ -773,7 +772,7 @@ def test_no_toml_installed_pyproject_toml_shorter_syntax(self) -> None:
with pytest.raises(ConfigError, match=msg):
coverage.Coverage()

@pytest.mark.skipif(sys.version_info >= (3, 11), reason="Python 3.11 has toml in stdlib")
@pytest.mark.skipif(env.PYVERSION >= (3, 11), reason="Python 3.11 has toml in stdlib")
def test_no_toml_installed_pyproject_no_coverage(self) -> None:
# It's ok to have non-coverage pyproject.toml without toml installed.
self.make_file("pyproject.toml", """\
Expand Down

0 comments on commit 962429c

Please sign in to comment.