Skip to content

Commit

Permalink
fixup! Tests: Added new commands to memray attach
Browse files Browse the repository at this point in the history
Test mutually exclusive options that do and don't accept parameters in one test function.
Also, ensure that the mutually exclusive option appears as a full word in the error message (otherwise the error message might contain '-f' as a substring of '--force')
  • Loading branch information
godlygeek committed Sep 14, 2023
1 parent 795efa2 commit 14e374e
Showing 1 changed file with 12 additions and 25 deletions.
37 changes: 12 additions & 25 deletions tests/unit/test_attach.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,26 +26,27 @@ class TestAttachSubCommandOptions:
@pytest.mark.parametrize(
"option",
[
"--native",
"--force",
"-f",
"--aggregate",
"--follow-fork",
"--trace-python-allocators",
"--no-compress",
["--output", "foo"],
["-o", "foo"],
["--native"],
["--force"],
["-f"],
["--aggregate"],
["--follow-fork"],
["--trace-python-allocators"],
["--no-compress"],
],
)
def test_memray_attach_stop_tracking_option_with_other_options(
self, option, capsys
):
# WHEN
with pytest.raises(SystemExit):
main(["attach", "1234", "--stop-tracking", option])
main(["attach", "1234", "--stop-tracking", *option])

captured = capsys.readouterr()
assert (
"Can't use --stop-tracking with" in captured.err and option in captured.err
)
assert "Can't use --stop-tracking with" in captured.err
assert option[0] in captured.err.split()

@pytest.mark.parametrize(
"arg1,arg2",
Expand All @@ -69,17 +70,3 @@ def test_memray_attach_stop_tracking_option_with_other_mode_options(
f"argument {arg2_name}: not allowed with argument {arg1_name}"
in captured.err
)

@pytest.mark.parametrize(
"option, argument",
[("--output", "test.bin")],
)
def test_memray_attach_stop_tracking_option_with_output_options(
self, option, argument, capsys
):
# WHEN
with pytest.raises(SystemExit):
main(["attach", "1234", "--stop-tracking", option, argument])

captured = capsys.readouterr()
assert f"Can't use --stop-tracking with {option}" in captured.err

0 comments on commit 14e374e

Please sign in to comment.