Merge pull request #6316 from cb109/make-keyword-expression-matching-case-insensitive
Make keyword expression matching case-insensitive
This commit is contained in:
commit
cbb2f9541b
|
@ -53,8 +53,8 @@ repos:
|
||||||
- id: changelogs-rst
|
- id: changelogs-rst
|
||||||
name: changelog filenames
|
name: changelog filenames
|
||||||
language: fail
|
language: fail
|
||||||
entry: 'changelog files must be named ####.(feature|bugfix|doc|deprecation|removal|vendor|trivial).rst'
|
entry: 'changelog files must be named ####.(breaking|bugfix|deprecation|doc|feature|improvement|trivial|vendor).rst'
|
||||||
exclude: changelog/(\d+\.(feature|improvement|bugfix|doc|deprecation|removal|vendor|trivial).rst|README.rst|_template.rst)
|
exclude: changelog/(\d+\.(breaking|bugfix|deprecation|doc|feature|improvement|trivial|vendor).rst|README.rst|_template.rst)
|
||||||
files: ^changelog/
|
files: ^changelog/
|
||||||
- id: py-deprecated
|
- id: py-deprecated
|
||||||
name: py library is deprecated
|
name: py library is deprecated
|
||||||
|
|
5
AUTHORS
5
AUTHORS
|
@ -60,12 +60,12 @@ Christian Fetzer
|
||||||
Christian Neumüller
|
Christian Neumüller
|
||||||
Christian Theunert
|
Christian Theunert
|
||||||
Christian Tismer
|
Christian Tismer
|
||||||
Christopher Gilling
|
Christoph Buelter
|
||||||
Christopher Dignam
|
Christopher Dignam
|
||||||
|
Christopher Gilling
|
||||||
CrazyMerlyn
|
CrazyMerlyn
|
||||||
Cyrus Maden
|
Cyrus Maden
|
||||||
Damian Skrzypczak
|
Damian Skrzypczak
|
||||||
Dhiren Serai
|
|
||||||
Daniel Grana
|
Daniel Grana
|
||||||
Daniel Hahler
|
Daniel Hahler
|
||||||
Daniel Nuri
|
Daniel Nuri
|
||||||
|
@ -80,6 +80,7 @@ David Szotten
|
||||||
David Vierra
|
David Vierra
|
||||||
Daw-Ran Liou
|
Daw-Ran Liou
|
||||||
Denis Kirisov
|
Denis Kirisov
|
||||||
|
Dhiren Serai
|
||||||
Diego Russo
|
Diego Russo
|
||||||
Dmitry Dygalo
|
Dmitry Dygalo
|
||||||
Dmitry Pribysh
|
Dmitry Pribysh
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
Matching of ``-k EXPRESSION`` to test names is now case-insensitive.
|
|
@ -18,7 +18,7 @@ Each file should be named like ``<ISSUE>.<TYPE>.rst``, where
|
||||||
* ``bugfix``: fixes a reported bug.
|
* ``bugfix``: fixes a reported bug.
|
||||||
* ``doc``: documentation improvement, like rewording an entire session or adding missing docs.
|
* ``doc``: documentation improvement, like rewording an entire session or adding missing docs.
|
||||||
* ``deprecation``: feature deprecation.
|
* ``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.
|
* ``vendor``: changes in packages vendored in pytest.
|
||||||
* ``trivial``: fixing a small typo or internal change that might be noteworthy.
|
* ``trivial``: fixing a small typo or internal change that might be noteworthy.
|
||||||
|
|
||||||
|
|
|
@ -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
|
exact match on markers that ``-m`` provides. This makes it easy to
|
||||||
select tests based on their names:
|
select tests based on their names:
|
||||||
|
|
||||||
|
.. versionadded: 5.4
|
||||||
|
|
||||||
|
The expression matching is now case-insensitive.
|
||||||
|
|
||||||
.. code-block:: pytest
|
.. code-block:: pytest
|
||||||
|
|
||||||
$ pytest -v -k http # running with the above defined example module
|
$ pytest -v -k http # running with the above defined example module
|
||||||
|
|
|
@ -94,8 +94,8 @@ Pytest supports several ways to run and select tests from the command-line.
|
||||||
|
|
||||||
pytest -k "MyClass and not method"
|
pytest -k "MyClass and not method"
|
||||||
|
|
||||||
This will run tests which contain names that match the given *string expression*, which can
|
This will run tests which contain names that match the given *string expression* (case-insensitive),
|
||||||
include Python operators that use filenames, class names and function names as variables.
|
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``.
|
The example above will run ``TestMyClass.test_something`` but not ``TestMyClass.test_method_simple``.
|
||||||
|
|
||||||
.. _nodeids:
|
.. _nodeids:
|
||||||
|
|
|
@ -16,8 +16,8 @@ title_format = "pytest {version} ({project_date})"
|
||||||
template = "changelog/_template.rst"
|
template = "changelog/_template.rst"
|
||||||
|
|
||||||
[[tool.towncrier.type]]
|
[[tool.towncrier.type]]
|
||||||
directory = "removal"
|
directory = "breaking"
|
||||||
name = "Removals"
|
name = "Breaking Changes"
|
||||||
showcontent = true
|
showcontent = true
|
||||||
|
|
||||||
[[tool.towncrier.type]]
|
[[tool.towncrier.type]]
|
||||||
|
|
|
@ -52,7 +52,8 @@ def pytest_addoption(parser):
|
||||||
"-k 'not test_method and not test_other' will eliminate the matches. "
|
"-k 'not test_method and not test_other' will eliminate the matches. "
|
||||||
"Additionally keywords are matched to classes and functions "
|
"Additionally keywords are matched to classes and functions "
|
||||||
"containing extra names in their 'extra_keyword_matches' set, "
|
"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(
|
group._addoption(
|
||||||
|
|
|
@ -57,7 +57,15 @@ class KeywordMapping:
|
||||||
return cls(mapped_names)
|
return cls(mapped_names)
|
||||||
|
|
||||||
def __getitem__(self, subname):
|
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:
|
if subname in name:
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
|
@ -809,6 +809,43 @@ class TestNodekeywords:
|
||||||
reprec = testdir.inline_run("-k repr")
|
reprec = testdir.inline_run("-k repr")
|
||||||
reprec.assertoutcome(passed=1, failed=0)
|
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(
|
COLLECTION_ERROR_PY_FILES = dict(
|
||||||
test_01_failure="""
|
test_01_failure="""
|
||||||
|
|
Loading…
Reference in New Issue