summaryrefslogtreecommitdiff
path: root/doc/en/example
diff options
context:
space:
mode:
authorRan Benita <ran@unusedvar.com>2020-04-25 13:38:53 +0300
committerRan Benita <ran@unusedvar.com>2020-05-01 12:59:06 +0300
commita718ad636304ab594eb95c8c64ac28a96354757d (patch)
tree17056b719c8d633c1a2d95788ca6bab9ca24600b /doc/en/example
parentbe68496440508b760ba1f988bcc63d1d09ace206 (diff)
downloadpytest-a718ad636304ab594eb95c8c64ac28a96354757d.tar.gz
Stop using Python's eval() for -m and -k
Previously, the expressions given to the `-m` and `-k` options were evaluated with `eval`. This causes a few issues: - Python keywords cannot be used. - Constants like numbers, None, True, False are not handled correctly. - Various syntax like numeric operators and `X if Y else Z` is supported unintentionally. - `eval()` is somewhat dangerous for arbitrary input. - Can fail in many ways so requires `except Exception`. The format we want to support is quite simple, so change to a custom parser. This fixes the issues above, and gives us full control of the format, so can be documented comprehensively and even be extended in the future if we wish.
Diffstat (limited to 'doc/en/example')
-rw-r--r--doc/en/example/markers.rst18
1 files changed, 3 insertions, 15 deletions
diff --git a/doc/en/example/markers.rst b/doc/en/example/markers.rst
index 467c2a2fa..e791f489d 100644
--- a/doc/en/example/markers.rst
+++ b/doc/en/example/markers.rst
@@ -141,14 +141,14 @@ Or select multiple nodes:
Using ``-k expr`` to select tests based on their name
-------------------------------------------------------
-.. versionadded: 2.0/2.3.4
+.. versionadded:: 2.0/2.3.4
You can use the ``-k`` command line option to specify an expression
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
+.. versionchanged:: 5.4
The expression matching is now case-insensitive.
@@ -198,20 +198,8 @@ Or to select "http" and "quick" tests:
===================== 2 passed, 2 deselected in 0.12s ======================
-.. note::
-
- If you are using expressions such as ``"X and Y"`` then both ``X`` and ``Y``
- need to be simple non-keyword names. For example, ``"pass"`` or ``"from"``
- will result in SyntaxErrors because ``"-k"`` evaluates the expression using
- Python's `eval`_ function.
-
-.. _`eval`: https://docs.python.org/3.6/library/functions.html#eval
-
+You can use ``and``, ``or``, ``not`` and parentheses.
- However, if the ``"-k"`` argument is a simple string, no such restrictions
- apply. Also ``"-k 'not STRING'"`` has no restrictions. You can also
- specify numbers like ``"-k 1.3"`` to match tests which are parametrized
- with the float ``"1.3"``.
Registering markers
-------------------------------------