Skip to content

Commit

Permalink
Allow pytest to detect configuration from pyproject.toml
Browse files Browse the repository at this point in the history
  • Loading branch information
ssbarnea committed Mar 13, 2023
1 parent ede30f9 commit 803a7f3
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
3 changes: 2 additions & 1 deletion .config/requirements.in
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
GitPython
diskcache >= 5.2.1
blessings
build>=0.3.1.post1 # py_package
click >= 7.1.2
colorama # for Windows
diskcache >= 5.2.1
importlib-metadata
pip>=21.0.1 # py_package
pluggy
Expand All @@ -12,5 +12,6 @@ pyyaml
rich >= 9.0
shellingham
subprocess-tee >= 0.3.1
tomli >= 1.1.0 ; python_version < "3.11"
twine>=3.4.1 # py_package
typer
15 changes: 15 additions & 0 deletions src/mk/loaders.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
"""Wrappers for loading different configuration files."""
from pathlib import Path

try:
import tomllib # type: ignore
except ModuleNotFoundError:
import tomli as tomllib # type: ignore


def load_toml(file: Path) -> dict:
"""Load a TOML file if exists or return empty dictionary."""
if file.is_file():
with open(file, "rb") as handle:
return tomllib.load(handle)
return {}
4 changes: 4 additions & 0 deletions src/mk/tools/pytest.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from typing import List, Optional

from mk.exec import run_or_fail
from mk.loaders import load_toml
from mk.tools import Action, Tool


Expand All @@ -26,6 +27,9 @@ def run(self, action: Optional[Action] = None) -> None:
def is_present(self, path: Path) -> bool:
if os.path.isfile(path / "pytest.ini"):
return True
data = load_toml(path / "pyproject.toml")
if data and data.get("tool", {}).get("pytest"):
return True
return False

def actions(self) -> List[Action]:
Expand Down

0 comments on commit 803a7f3

Please sign in to comment.