summaryrefslogtreecommitdiff
path: root/testing/test_main.py
diff options
context:
space:
mode:
authorPrashant Anand <p-anand@mercari.com>2020-06-09 09:54:22 +0900
committerGitHub <noreply@github.com>2020-06-08 21:54:22 -0300
commite78207c936c43478aa5d5531d7c0b90aa240c9e0 (patch)
tree8120bd4487471745a226cd576e6a71ce458793e0 /testing/test_main.py
parenta76855912b599d53865c9019b10ae934875fbe04 (diff)
downloadpytest-e78207c936c43478aa5d5531d7c0b90aa240c9e0.tar.gz
7119: data loss with mistyped --basetemp (#7170)
Co-authored-by: Bruno Oliveira <nicoddemus@gmail.com> Co-authored-by: Ran Benita <ran@unusedvar.com>
Diffstat (limited to 'testing/test_main.py')
-rw-r--r--testing/test_main.py23
1 files changed, 23 insertions, 0 deletions
diff --git a/testing/test_main.py b/testing/test_main.py
index 07aca3a1e..ee8349a9f 100644
--- a/testing/test_main.py
+++ b/testing/test_main.py
@@ -1,7 +1,9 @@
+import argparse
from typing import Optional
import pytest
from _pytest.config import ExitCode
+from _pytest.main import validate_basetemp
from _pytest.pytester import Testdir
@@ -75,3 +77,24 @@ def test_wrap_session_exit_sessionfinish(
assert result.ret == ExitCode.NO_TESTS_COLLECTED
assert result.stdout.lines[-1] == "collected 0 items"
assert result.stderr.lines == ["Exit: exit_pytest_sessionfinish"]
+
+
+@pytest.mark.parametrize("basetemp", ["foo", "foo/bar"])
+def test_validate_basetemp_ok(tmp_path, basetemp, monkeypatch):
+ monkeypatch.chdir(str(tmp_path))
+ validate_basetemp(tmp_path / basetemp)
+
+
+@pytest.mark.parametrize("basetemp", ["", ".", ".."])
+def test_validate_basetemp_fails(tmp_path, basetemp, monkeypatch):
+ monkeypatch.chdir(str(tmp_path))
+ msg = "basetemp must not be empty, the current working directory or any parent directory of it"
+ with pytest.raises(argparse.ArgumentTypeError, match=msg):
+ if basetemp:
+ basetemp = tmp_path / basetemp
+ validate_basetemp(basetemp)
+
+
+def test_validate_basetemp_integration(testdir):
+ result = testdir.runpytest("--basetemp=.")
+ result.stderr.fnmatch_lines("*basetemp must not be*")