Configure ruff in pyproject.toml and apply its fixes: modern annotations (X | None, builtin generics, collections.abc), sorted imports, explicit stacklevel in test warnings.
31 lines
777 B
Python
31 lines
777 B
Python
"""Shared fixtures for the simple_backup tests"""
|
|
|
|
import sys
|
|
from collections.abc import Callable
|
|
|
|
import pytest
|
|
|
|
from simple_backup import simple_backup as sb
|
|
|
|
|
|
@pytest.fixture(autouse=True)
|
|
def no_side_effects(monkeypatch: pytest.MonkeyPatch) -> None:
|
|
"""Keep tests out of the systemd journal and the desktop notifications"""
|
|
|
|
if hasattr(sb, 'j_handler'):
|
|
sb.logger.removeHandler(sb.j_handler)
|
|
|
|
monkeypatch.setattr(sb, '_notify', lambda text: None)
|
|
|
|
|
|
@pytest.fixture
|
|
def run_cli(monkeypatch: pytest.MonkeyPatch) -> Callable[..., int]:
|
|
"""Run simple_backup() with the given command line arguments"""
|
|
|
|
def run(*argv: str) -> int:
|
|
monkeypatch.setattr(sys, 'argv', ['simple_backup', *argv])
|
|
|
|
return sb.simple_backup()
|
|
|
|
return run
|