Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 19 additions & 4 deletions tests/feature/test_feature_base_dir.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,33 @@
"""Test feature base dir."""
import pkg_resources
import pytest

NOT_EXISTING_FEATURE_PATHS = [".", "/does/not/exist/"]

assert_outcomes_extra = pkg_resources.get_distribution("pytest").parsed_version >= pkg_resources.parse_version("7.0.0")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that pkg_resources is a third-party dependency (part of setuptools, but not the stdlib), and is officially discouraged:

Use of pkg_resources is discouraged in favor of importlib.resources, importlib.metadata, and their backports (resources, metadata). Please consider using those libraries instead of pkg_resources.

Note that importlib.metadata also only was added in Python 3.8. However, pytest 7 added pytest.version_tuple, so you could get the version from there (and assume False when it does not exist).

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pytest_bdd supports pytest<7 and python=3.7, so for now - this is not an option



@pytest.mark.parametrize("base_dir", NOT_EXISTING_FEATURE_PATHS)
def test_feature_path_not_found(testdir, base_dir):
"""Test feature base dir."""
prepare_testdir(testdir, base_dir)

result = testdir.runpytest("-k", "test_not_found_by_ini")
result.assert_outcomes(passed=2)
if assert_outcomes_extra:
result.assert_outcomes(passed=2, deselected=8)
else:
result.assert_outcomes(passed=2)


def test_feature_path_ok(testdir):
base_dir = "features"
prepare_testdir(testdir, base_dir)

result = testdir.runpytest("-k", "test_ok_by_ini")
result.assert_outcomes(passed=2)
if assert_outcomes_extra:
result.assert_outcomes(passed=2, deselected=8)
else:
result.assert_outcomes(passed=2)


def test_feature_path_by_param_not_found(testdir):
Expand All @@ -28,7 +37,10 @@ def test_feature_path_by_param_not_found(testdir):
prepare_testdir(testdir, base_dir)

result = testdir.runpytest("-k", "test_not_found_by_param")
result.assert_outcomes(passed=4)
if assert_outcomes_extra:
result.assert_outcomes(passed=4, deselected=6)
else:
result.assert_outcomes(passed=4)


@pytest.mark.parametrize("base_dir", NOT_EXISTING_FEATURE_PATHS)
Expand All @@ -38,7 +50,10 @@ def test_feature_path_by_param_ok(testdir, base_dir):
prepare_testdir(testdir, base_dir)

result = testdir.runpytest("-k", "test_ok_by_param")
result.assert_outcomes(passed=2)
if assert_outcomes_extra:
result.assert_outcomes(passed=2, deselected=8)
else:
result.assert_outcomes(passed=2)


def prepare_testdir(testdir, ini_base_dir):
Expand Down
25 changes: 21 additions & 4 deletions tests/feature/test_steps.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import textwrap

import pkg_resources

assert_outcomes_extra = pkg_resources.get_distribution("pytest").parsed_version >= pkg_resources.parse_version("7.0.0")


def test_steps(testdir):
testdir.makefile(
Expand Down Expand Up @@ -466,22 +470,35 @@ def test_when_step_validation_error():
"""
)
result = testdir.runpytest("-k test_when_fails_inline", "-vv")
result.assert_outcomes(failed=1)
if assert_outcomes_extra:
result.assert_outcomes(failed=1, deselected=3)
else:
result.assert_outcomes(failed=1)

result.stdout.fnmatch_lines(["*test_when_fails_inline*FAILED"])
assert "INTERNALERROR" not in result.stdout.str()

result = testdir.runpytest("-k test_when_fails_decorated", "-vv")
result.assert_outcomes(failed=1)
if assert_outcomes_extra:
result.assert_outcomes(failed=1, deselected=3)
else:
result.assert_outcomes(failed=1)
result.stdout.fnmatch_lines(["*test_when_fails_decorated*FAILED"])
assert "INTERNALERROR" not in result.stdout.str()

result = testdir.runpytest("-k test_when_not_found", "-vv")
result.assert_outcomes(failed=1)
if assert_outcomes_extra:
result.assert_outcomes(failed=1, deselected=3)
else:
result.assert_outcomes(failed=1)
result.stdout.fnmatch_lines(["*test_when_not_found*FAILED"])
assert "INTERNALERROR" not in result.stdout.str()

result = testdir.runpytest("-k test_when_step_validation_error", "-vv")
result.assert_outcomes(failed=1)
if assert_outcomes_extra:
result.assert_outcomes(failed=1, deselected=3)
else:
result.assert_outcomes(failed=1)
result.stdout.fnmatch_lines(["*test_when_step_validation_error*FAILED"])
assert "INTERNALERROR" not in result.stdout.str()

Expand Down