diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 0c89a6272..64f3f32ac 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -53,8 +53,8 @@ repos: - id: changelogs-rst name: changelog filenames language: fail - entry: 'changelog files must be named ####.(feature|bugfix|doc|deprecation|removal|vendor|trivial).rst' - exclude: changelog/(\d+\.(feature|improvement|bugfix|doc|deprecation|removal|vendor|trivial).rst|README.rst|_template.rst) + entry: 'changelog files must be named ####.(breaking|bugfix|deprecation|doc|feature|improvement|trivial|vendor).rst' + exclude: changelog/(\d+\.(breaking|bugfix|deprecation|doc|feature|improvement|trivial|vendor).rst|README.rst|_template.rst) files: ^changelog/ - id: py-deprecated name: py library is deprecated diff --git a/AUTHORS b/AUTHORS index 163b317bc..c8d770aec 100644 --- a/AUTHORS +++ b/AUTHORS @@ -60,12 +60,12 @@ Christian Fetzer Christian Neumüller Christian Theunert Christian Tismer -Christopher Gilling +Christoph Buelter Christopher Dignam +Christopher Gilling CrazyMerlyn Cyrus Maden Damian Skrzypczak -Dhiren Serai Daniel Grana Daniel Hahler Daniel Nuri @@ -80,6 +80,7 @@ David Szotten David Vierra Daw-Ran Liou Denis Kirisov +Dhiren Serai Diego Russo Dmitry Dygalo Dmitry Pribysh diff --git a/changelog/6316.breaking.rst b/changelog/6316.breaking.rst new file mode 100644 index 000000000..6ab7d8717 --- /dev/null +++ b/changelog/6316.breaking.rst @@ -0,0 +1 @@ +Matching of ``-k EXPRESSION`` to test names is now case-insensitive. diff --git a/changelog/README.rst b/changelog/README.rst index adabc9ca1..dd0e7dfea 100644 --- a/changelog/README.rst +++ b/changelog/README.rst @@ -18,7 +18,7 @@ Each file should be named like ``..rst``, where * ``bugfix``: fixes a reported bug. * ``doc``: documentation improvement, like rewording an entire session or adding missing docs. * ``deprecation``: feature deprecation. -* ``removal``: feature removal. +* ``breaking``: a change which may break existing suites, such as feature removal or behavior change. * ``vendor``: changes in packages vendored in pytest. * ``trivial``: fixing a small typo or internal change that might be noteworthy. diff --git a/doc/en/example/markers.rst b/doc/en/example/markers.rst index 8143b3fd4..e83beedd0 100644 --- a/doc/en/example/markers.rst +++ b/doc/en/example/markers.rst @@ -148,6 +148,10 @@ which implements a substring match on the test names instead of the exact match on markers that ``-m`` provides. This makes it easy to select tests based on their names: +.. versionadded: 5.4 + +The expression matching is now case-insensitive. + .. code-block:: pytest $ pytest -v -k http # running with the above defined example module diff --git a/doc/en/usage.rst b/doc/en/usage.rst index 245a67b68..527794823 100644 --- a/doc/en/usage.rst +++ b/doc/en/usage.rst @@ -94,8 +94,8 @@ Pytest supports several ways to run and select tests from the command-line. pytest -k "MyClass and not method" -This will run tests which contain names that match the given *string expression*, which can -include Python operators that use filenames, class names and function names as variables. +This will run tests which contain names that match the given *string expression* (case-insensitive), +which can include Python operators that use filenames, class names and function names as variables. The example above will run ``TestMyClass.test_something`` but not ``TestMyClass.test_method_simple``. .. _nodeids: diff --git a/pyproject.toml b/pyproject.toml index 31bf3bf4b..4ac1fd754 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -16,8 +16,8 @@ title_format = "pytest {version} ({project_date})" template = "changelog/_template.rst" [[tool.towncrier.type]] - directory = "removal" - name = "Removals" + directory = "breaking" + name = "Breaking Changes" showcontent = true [[tool.towncrier.type]] diff --git a/src/_pytest/mark/__init__.py b/src/_pytest/mark/__init__.py index e21e234e7..f493bd839 100644 --- a/src/_pytest/mark/__init__.py +++ b/src/_pytest/mark/__init__.py @@ -52,7 +52,8 @@ def pytest_addoption(parser): "-k 'not test_method and not test_other' will eliminate the matches. " "Additionally keywords are matched to classes and functions " "containing extra names in their 'extra_keyword_matches' set, " - "as well as functions which have names assigned directly to them.", + "as well as functions which have names assigned directly to them. " + "The matching is case-insensitive.", ) group._addoption( diff --git a/src/_pytest/mark/legacy.py b/src/_pytest/mark/legacy.py index 3721e3b02..766b8f9bd 100644 --- a/src/_pytest/mark/legacy.py +++ b/src/_pytest/mark/legacy.py @@ -57,7 +57,15 @@ class KeywordMapping: return cls(mapped_names) def __getitem__(self, subname): - for name in self._names: + """Return whether subname is included within stored names. + + The string inclusion check is case-insensitive. + + """ + subname = subname.lower() + names = (name.lower() for name in self._names) + + for name in names: if subname in name: return True return False diff --git a/testing/test_collection.py b/testing/test_collection.py index 624e9dd4e..e7bcb60a9 100644 --- a/testing/test_collection.py +++ b/testing/test_collection.py @@ -809,6 +809,43 @@ class TestNodekeywords: reprec = testdir.inline_run("-k repr") reprec.assertoutcome(passed=1, failed=0) + def test_keyword_matching_is_case_insensitive_by_default(self, testdir): + """Check that selection via -k EXPRESSION is case-insensitive. + + Since markers are also added to the node keywords, they too can + be matched without having to think about case sensitivity. + + """ + testdir.makepyfile( + """ + import pytest + + def test_sPeCiFiCToPiC_1(): + assert True + + class TestSpecificTopic_2: + def test(self): + assert True + + @pytest.mark.sPeCiFiCToPic_3 + def test(): + assert True + + @pytest.mark.sPeCiFiCToPic_4 + class Test: + def test(self): + assert True + + def test_failing_5(): + assert False, "This should not match" + + """ + ) + num_matching_tests = 4 + for expression in ("specifictopic", "SPECIFICTOPIC", "SpecificTopic"): + reprec = testdir.inline_run("-k " + expression) + reprec.assertoutcome(passed=num_matching_tests, failed=0) + COLLECTION_ERROR_PY_FILES = dict( test_01_failure="""