Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skip content tests when file does not exist. #152

Merged
merged 14 commits into from
Nov 11, 2022
Merged
1 change: 1 addition & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Changelog

version 1.7.0-dev
---------------------------
+ Skip tests searching in non existing file
+ Test and support for Python 3.11.
+ Add ``--stderr-bytes`` or ``--sb`` option to change the maximum
number of bytes to display for the stderr and stdout on
Expand Down
24 changes: 9 additions & 15 deletions src/pytest_workflow/content_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,9 @@ def runtest(self):
were we are looking for multiple words (variants / sequences). """
# Wait for thread to complete.
self.parent.thread.join()
assert not self.parent.file_not_found
if self.parent.file_not_found:
pytest.skip(f"'{self.content_name}' was not found so cannot be "
f"searched")
if self.regex:
assert ((self.string in self.parent.found_patterns) ==
self.should_contain)
Expand All @@ -253,17 +255,9 @@ def runtest(self):
self.should_contain)

def repr_failure(self, excinfo, style=None):
if self.parent.file_not_found:
containing = ("containing" if self.should_contain else
"not containing")
return (
f"'{self.content_name}' does not exist and cannot be searched "
f"for {containing} '{self.string}'."
)
else:
found = "not found" if self.should_contain else "found"
should = "should" if self.should_contain else "should not"
return (
f"'{self.string}' was {found} in {self.content_name} "
f"while it {should} be there."
)
found = "not found" if self.should_contain else "found"
should = "should" if self.should_contain else "should not"
return (
f"'{self.string}' was {found} in {self.content_name} "
f"while it {should} be there."
)
19 changes: 0 additions & 19 deletions tests/test_fail_messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,25 +111,6 @@
"'grep --help' was found in 'fail_test': stderr while "
"it should not be there"),
("""\
- name: file_not_exist
command: echo moo
files:
- path: moo.txt
contains:
- "moo"
""",
"moo.txt' does not exist and cannot be searched for containing 'moo'."),
("""\
- name: file_not_exist
command: echo moo
files:
- path: moo.txt
must_not_contain:
- "miaow"
""",
"moo.txt' does not exist and cannot be searched for "
"not containing 'miaow'."),
("""\
- name: simple echo
command: "echo Hello, world"
stdout:
Expand Down
46 changes: 46 additions & 0 deletions tests/test_skip_tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Copyright (C) 2018 Leiden University Medical Center
# This file is part of pytest-workflow
#
# pytest-workflow is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# pytest-workflow is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with pytest-workflow. If not, see <https://www.gnu.org/licenses/

import textwrap

SKIP_TESTS = textwrap.dedent("""\
- name: wall_test
command: echo "testing"
files:
- path: test.txt
contains:
- "brie"
- path: test2.txt
contains:
- "halloumi"
must_not_contain:
- "gorgonzola"

- name: wall3_test
command: bash -c "echo 'testing' > test3.txt"
files:
- path: test3.txt
contains:
- "kaas"
must_not_contain:
- "testing"
""")


def test_skips(pytester):
pytester.makefile(".yml", test=SKIP_TESTS)
result = pytester.runpytest("-v").parseoutcomes()
assert {"failed": 4, "passed": 3, "skipped": 3} == result