Exit with simple_backup()'s return code when run as a script
This commit is contained in:
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user