From c4533f458d85c9bf365eb012ee74d4592579de3b Mon Sep 17 00:00:00 2001 From: Beda Kraus Date: Wed, 24 Jan 2024 14:57:13 +0100 Subject: [PATCH 1/2] Added pytest to 'make qa' Signed-off-by: Beda Kraus --- Makefile | 4 ++-- REQUIREMENTS.qa.txt | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 9670f80..c3addf7 100644 --- a/Makefile +++ b/Makefile @@ -44,5 +44,5 @@ $(PYTHON_TESTING_ENV)/.created: REQUIREMENTS.qa.txt qa: $(PYTHON_TESTING_ENV)/.created . $(PYTHON_TESTING_ENV)/bin/activate && \ black --check --diff . && \ - flake8 - + flake8 && \ + python3 -m pytest -vv diff --git a/REQUIREMENTS.qa.txt b/REQUIREMENTS.qa.txt index e8808ee..f52ea01 100644 --- a/REQUIREMENTS.qa.txt +++ b/REQUIREMENTS.qa.txt @@ -2,4 +2,5 @@ black flake8 flake8-pyproject flake8-bugbear - +pytest +pytest-mock From b7613d85161ba33838469f7339fe78163dc86b75 Mon Sep 17 00:00:00 2001 From: Beda Kraus Date: Wed, 24 Jan 2024 14:58:20 +0100 Subject: [PATCH 2/2] Added error messages to test_cli.py Signed-off-by: Beda Kraus --- tests/test_cli.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/tests/test_cli.py b/tests/test_cli.py index b7390bb..3921811 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -12,7 +12,7 @@ def test_usage(capsys, mocker): usbsdmux.__main__.main() captured = capsys.readouterr() assert captured.out == "" - assert captured.err.startswith("usage: usbsdmux") + assert captured.err.startswith("usage: usbsdmux"), "Invalid help: does not start with 'usage: usbsdmux'" def test_help_in_readme(capsys, mocker): @@ -21,8 +21,8 @@ def test_help_in_readme(capsys, mocker): with pytest.raises(SystemExit): usbsdmux.__main__.main() captured = capsys.readouterr() - assert captured.out.startswith("usage: usbsdmux") - assert captured.err == "" + assert captured.out.startswith("usage: usbsdmux"), "Invalid help: does not start with 'usage: usbsdmux'" + assert captured.err == "", f"Execution of 'usbsdmux -h' failed: \n{captured.err}" readme_path = os.path.join(os.path.dirname(__file__), "../", "README.rst") readme_lines = None @@ -35,9 +35,11 @@ def test_help_in_readme(capsys, mocker): break readme_lines.append(line) - assert readme_lines is not None + assert readme_lines is not None, "Bash command not found. Did you include ' $ usbsdmux -h'?" + assert readme_lines, "No output lines found. Did you indent the output correctly?" + del readme_lines[-1] # remove trailing empty line output_lines = [f" {line}".rstrip() for line in captured.out.splitlines()] - assert output_lines == readme_lines + assert output_lines == readme_lines, "Output of 'usbsdmux -h' does not match output in README.rst"