From e24b6b03886a36461af3381637a33fd8de6bee06 Mon Sep 17 00:00:00 2001 From: Christoph Buelter Date: Thu, 5 Dec 2019 13:56:45 +0100 Subject: [PATCH] Change -k EXPRESSION matching to be case-insensitive --- src/_pytest/mark/legacy.py | 10 +++++++++- testing/test_collection.py | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/src/_pytest/mark/legacy.py b/src/_pytest/mark/legacy.py index 3721e3b02..651288cb8 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..fcbfcf5fb 100644 --- a/testing/test_collection.py +++ b/testing/test_collection.py @@ -809,6 +809,40 @@ 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 + + """ + ) + num_all_tests_passed = 4 + for expression in ("specifictopic", "SPECIFICTOPIC", "SpecificTopic"): + reprec = testdir.inline_run("-k " + expression) + reprec.assertoutcome(passed=num_all_tests_passed, failed=0) + COLLECTION_ERROR_PY_FILES = dict( test_01_failure="""