Skip to content

Commit

Permalink
test: Support setting cmd=None to require no command, for unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
scop committed Jul 11, 2018
1 parent 75628f7 commit 8884ceb
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions test/t/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,11 @@ def bash(request) -> pexpect.spawn:

# Use command name from marker if set, or grab from test filename
cmd = None
cmd_found = False
marker = request.node.get_marker("bashcomp")
if marker:
cmd = marker.kwargs.get("cmd")
cmd_found = "cmd" in marker.kwargs
# Run pre-test commands, early so they're usable in skipif
for pre_cmd in marker.kwargs.get("pre_cmds", []):
assert_bash_exec(bash, pre_cmd)
Expand All @@ -69,13 +71,13 @@ def bash(request) -> pexpect.spawn:
bash.close()
pytest.skip(skipif)
return
if not cmd:
if not cmd_found:
match = re.search(
r"^test_(.+)\.py$", os.path.basename(str(request.fspath)))
if match:
cmd = match.group(1)

if is_testable(bash, cmd):
if cmd_found or is_testable(bash, cmd):
before_env = get_env(bash)
yield bash
diff_env(before_env, get_env(bash),
Expand Down

0 comments on commit 8884ceb

Please sign in to comment.