Exit with simple_backup()'s return code when run as a script

This commit is contained in:
Fuxino
2026-10-21 22:37:55 +02:00
parent 9e6aadf7d3
commit b54f7e1817
2 changed files with 17 additions and 1 deletions
+1 -1
View File
@@ -1192,4 +1192,4 @@ def simple_backup() -> int:
if __name__ == '__main__':
simple_backup()
sys.exit(simple_backup())
+16
View File
@@ -2,6 +2,8 @@
import os
import pwd
import subprocess
import sys
from collections.abc import Callable
from pathlib import Path
from typing import Any
@@ -325,6 +327,20 @@ class TestDetectUser:
assert sb._detect_user() == USER
def test_run_as_script(tmp_path: Path) -> None:
"""Running the module directly passes simple_backup()'s return code to the shell"""
repo = Path(sb.__file__).resolve().parents[1]
env = {**os.environ, 'PYTHONPATH': str(repo), 'HOME': str(tmp_path)}
# No config file and no inputs: check_params() returns 1
result = subprocess.run([sys.executable, '-m', 'simple_backup.simple_backup', '--no-syslog',
'-c', str(tmp_path / 'missing.conf')], env=env, cwd=tmp_path,
capture_output=True, check=False)
assert result.returncode == 1
class TestTargetUid:
@pytest.mark.usefixtures('as_user')
def test_non_root(self) -> None: