Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge master into features #4068

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
c61ff31
Fix #3539: reload module with assertion rewrite import hook
iwanb Sep 23, 2018
eca3e78
Merge pull request #4022 from iwanb/fix_reload
RonnyPfannschmidt Sep 23, 2018
4474bee
Typo fix [ci skip]
asottile Sep 24, 2018
9899b8f
Add an example on how to update config.warn calls
nicoddemus Sep 24, 2018
2b76233
add documentation of register_assert_rewrite
hjwp Sep 25, 2018
97748b6
mention conftest.py as a good place to do it.
hjwp Sep 25, 2018
11442f2
fix rst syntax thing
hjwp Sep 25, 2018
19ec300
fix rst syntax again
hjwp Sep 25, 2018
b03bad5
Fix linting
nicoddemus Sep 25, 2018
e85edf5
Merge pull request #4029 from nicoddemus/warnings-example-deprecation…
blueyed Sep 25, 2018
b1fbb2a
Merge pull request #4032 from hjwp/patch-1
nicoddemus Sep 25, 2018
1636522
Document that item parameter of pytest_warning_captured hook is depre…
nicoddemus Sep 25, 2018
f9ab81a
Exclude empty reports for passed tests
ods Sep 26, 2018
6be2136
Ensure user_properties is a list
Zac-HD Sep 26, 2018
a089a95
Succinct definition of user_properties
Zac-HD Sep 26, 2018
808df48
Test for excluding empty reports for passed tests
ods Sep 26, 2018
ba5630e
Simplify test_pytest_plugins_in_non_top_level_conftest_deprecated
nicoddemus Sep 26, 2018
32c5a11
Do not issue non-top-level conftest warning when --pyargs is used
nicoddemus Sep 26, 2018
44d29d8
Changelog entry on excluding empty reports for passed tests
ods Sep 26, 2018
2d06927
Merge pull request #4040 from ods/summary_passes_less_noisy
nicoddemus Sep 27, 2018
d2fc7ca
Merge pull request #4041 from Zac-HD/user-properties-type
nicoddemus Sep 27, 2018
783019a
Rename 4040.trivial.rst to 4040.bugfix.rst
nicoddemus Sep 27, 2018
3c23b5b
Merge pull request #4037 from nicoddemus/deprecate-item-warnings-capt…
RonnyPfannschmidt Sep 27, 2018
d8d7f73
Merge pull request #4045 from nicoddemus/root-conftest-warning-workar…
nicoddemus Sep 27, 2018
c2179c3
Improve error messaging when invalid syntax is passed to the -m option
jeffreyrack Oct 1, 2018
7a6d16c
Adding .rst to end of changelog fragment filename.
jeffreyrack Oct 1, 2018
5d2d64c
Merge pull request #4057 from jeffreyrack/4051-improve-error-messaging
RonnyPfannschmidt Oct 1, 2018
732cc26
Add possible values for fixture scope to docs
cacoze Oct 1, 2018
4dc73bd
Update changelog
cacoze Oct 1, 2018
d24a7e6
Issue warning if Monkeypatch.setenv/delenv receive non-strings in Pyt…
nicoddemus Sep 29, 2018
20d0f0e
Improve changelog for #4051
nicoddemus Oct 1, 2018
dd59ed3
Merge pull request #4059 from labcodes/documenting-scopes
nicoddemus Oct 1, 2018
5e7d427
Merge pull request #4060 from nicoddemus/4051-changelog
nicoddemus Oct 1, 2018
bc009a8
Fix test to comply with pypy 6.0
nicoddemus Sep 30, 2018
9d971d3
Hide internal pytest.warns traceback
nicoddemus Oct 1, 2018
1a323fb
Show a warning when non-str is given to Monkeypatch.setenv
nicoddemus Oct 1, 2018
25fe370
Merge pull request #4056 from nicoddemus/unicode-vars
nicoddemus Oct 2, 2018
d3673c7
Preparing release version 3.8.2
asottile Oct 2, 2018
df435fa
Merge pull request #4065 from asottile/release-3.8.2
asottile Oct 2, 2018
1101a20
Merge remote-tracking branch 'upstream/master' into merge-master-into…
nicoddemus Oct 2, 2018
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
6 changes: 4 additions & 2 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Ahn Ki-Wook
Alan Velasco
Alexander Johnson
Alexei Kozlenok
Allan Feldman
Anatoly Bubenkoff
Anders Hovmöller
Andras Tim
Expand Down Expand Up @@ -94,6 +95,7 @@ Hui Wang (coldnight)
Ian Bicking
Ian Lesperance
Ionuț Turturică
Iwan Briquemont
Jaap Broekhuizen
Jan Balster
Janne Vanhala
Expand Down Expand Up @@ -179,6 +181,7 @@ Raphael Pierzina
Raquel Alegre
Ravi Chandra
Roberto Polli
Roland Puntaier
Romain Dorgueil
Roman Bolshakov
Ronny Pfannschmidt
Expand Down Expand Up @@ -223,6 +226,5 @@ Wim Glenn
Wouter van Ackooy
Xuan Luong
Xuecong Liao
Zac Hatfield-Dodds
Zoltán Máté
Roland Puntaier
Allan Feldman
52 changes: 52 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,58 @@ with advance notice in the **Deprecations** section of releases.

.. towncrier release notes start

pytest 3.8.2 (2018-10-02)
=========================

Deprecations and Removals
-------------------------

- `#4036 <https://github.com/pytest-dev/pytest/issues/4036>`_: The ``item`` parameter of ``pytest_warning_captured`` hook is now documented as deprecated. We realized only after
the ``3.8`` release that this parameter is incompatible with ``pytest-xdist``.

Our policy is to not deprecate features during bugfix releases, but in this case we believe it makes sense as we are
only documenting it as deprecated, without issuing warnings which might potentially break test suites. This will get
the word out that hook implementers should not use this parameter at all.

In a future release ``item`` will always be ``None`` and will emit a proper warning when a hook implementation
makes use of it.



Bug Fixes
---------

- `#3539 <https://github.com/pytest-dev/pytest/issues/3539>`_: Fix reload on assertion rewritten modules.


- `#4034 <https://github.com/pytest-dev/pytest/issues/4034>`_: The ``.user_properties`` attribute of ``TestReport`` objects is a list
of (name, value) tuples, but could sometimes be instantiated as a tuple
of tuples. It is now always a list.


- `#4039 <https://github.com/pytest-dev/pytest/issues/4039>`_: No longer issue warnings about using ``pytest_plugins`` in non-top-level directories when using ``--pyargs``: the
current ``--pyargs`` mechanism is not reliable and might give false negatives.


- `#4040 <https://github.com/pytest-dev/pytest/issues/4040>`_: Exclude empty reports for passed tests when ``-rP`` option is used.


- `#4051 <https://github.com/pytest-dev/pytest/issues/4051>`_: Improve error message when an invalid Python expression is passed to the ``-m`` option.


- `#4056 <https://github.com/pytest-dev/pytest/issues/4056>`_: ``MonkeyPatch.setenv`` and ``MonkeyPatch.delenv`` issue a warning if the environment variable name is not ``str`` on Python 2.

In Python 2, adding ``unicode`` keys to ``os.environ`` causes problems with ``subprocess`` (and possible other modules),
making this a subtle bug specially susceptible when used with ``from __future__ import unicode_literals``.



Improved Documentation
----------------------

- `#3928 <https://github.com/pytest-dev/pytest/issues/3928>`_: Add possible values for fixture scope to docs.


pytest 3.8.1 (2018-09-22)
=========================

Expand Down
1 change: 1 addition & 0 deletions doc/en/announce/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Release announcements
:maxdepth: 2


release-3.8.2
release-3.8.1
release-3.8.0
release-3.7.4
Expand Down
28 changes: 28 additions & 0 deletions doc/en/announce/release-3.8.2.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
pytest-3.8.2
=======================================

pytest 3.8.2 has just been released to PyPI.

This is a bug-fix release, being a drop-in replacement. To upgrade::

pip install --upgrade pytest

The full changelog is available at https://docs.pytest.org/en/latest/changelog.html.

Thanks to all who contributed to this release, among them:

* Ankit Goel
* Anthony Sottile
* Bruno Oliveira
* Daniel Hahler
* Denis Otkidach
* Harry Percival
* Jeffrey Rackauckas
* Jose Carlos Menezes
* Ronny Pfannschmidt
* Zac-HD
* iwanb


Happy testing,
The pytest Development Team
8 changes: 6 additions & 2 deletions doc/en/assert.rst
Original file line number Diff line number Diff line change
Expand Up @@ -264,8 +264,12 @@ Advanced assertion introspection
Reporting details about a failing assertion is achieved by rewriting assert
statements before they are run. Rewritten assert statements put introspection
information into the assertion failure message. ``pytest`` only rewrites test
modules directly discovered by its test collection process, so asserts in
supporting modules which are not themselves test modules will not be rewritten.
modules directly discovered by its test collection process, so **asserts in
supporting modules which are not themselves test modules will not be rewritten**.

You can manually enable assertion rewriting for an imported module by calling
`register_assert_rewrite <https://docs.pytest.org/en/latest/writing_plugins.html#assertion-rewriting>`_
before you import it (a good place to do that is in ``conftest.py``).

.. note::

Expand Down
16 changes: 13 additions & 3 deletions doc/en/deprecations.rst
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,24 @@ message please contact the authors so they can change the code.
Those methods were part of the internal pytest warnings system, but since ``3.8`` pytest is using the builtin warning
system for its own warnings, so those two functions are now deprecated.

``Config.warn`` should be replaced by calls to the standard ``warnings.warn``.
``Config.warn`` should be replaced by calls to the standard ``warnings.warn``, example:

.. code-block:: python
config.warn("C1", "some warning")
Becomes:

.. code-block:: python
warnings.warn(pytest.PytestWarning("some warning"))
``Node.warn`` now supports two signatures:

* ``node.warn(PytestWarning("some message"))``: is now the recommended way to call this function.
* ``node.warn(PytestWarning("some message"))``: is now the **recommended** way to call this function.
The warning instance must be a PytestWarning or subclass.

* ``node.warn("CI", "some message")``: this code/message form is now deprecated and should be converted to the warning instance form above.
* ``node.warn("CI", "some message")``: this code/message form is now **deprecated** and should be converted to the warning instance form above.


``pytest_namespace``
Expand Down
16 changes: 8 additions & 8 deletions doc/en/example/markers.rst
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ You can then restrict a test run to only run tests marked with ``webtest``::

$ pytest -v -m webtest
=========================== test session starts ============================
platform linux -- Python 3.x.y, pytest-3.x.y, py-1.x.y, pluggy-0.x.y -- $PYTHON_PREFIX/bin/python3.6
platform linux -- Python 3.x.y, pytest-3.x.y, py-1.x.y, pluggy-0.x.y -- $PYTHON_PREFIX/bin/python
cachedir: .pytest_cache
rootdir: $REGENDOC_TMPDIR, inifile:
collecting ... collected 4 items / 3 deselected
Expand All @@ -44,7 +44,7 @@ Or the inverse, running all tests except the webtest ones::

$ pytest -v -m "not webtest"
=========================== test session starts ============================
platform linux -- Python 3.x.y, pytest-3.x.y, py-1.x.y, pluggy-0.x.y -- $PYTHON_PREFIX/bin/python3.6
platform linux -- Python 3.x.y, pytest-3.x.y, py-1.x.y, pluggy-0.x.y -- $PYTHON_PREFIX/bin/python
cachedir: .pytest_cache
rootdir: $REGENDOC_TMPDIR, inifile:
collecting ... collected 4 items / 1 deselected
Expand All @@ -64,7 +64,7 @@ tests based on their module, class, method, or function name::

$ pytest -v test_server.py::TestClass::test_method
=========================== test session starts ============================
platform linux -- Python 3.x.y, pytest-3.x.y, py-1.x.y, pluggy-0.x.y -- $PYTHON_PREFIX/bin/python3.6
platform linux -- Python 3.x.y, pytest-3.x.y, py-1.x.y, pluggy-0.x.y -- $PYTHON_PREFIX/bin/python
cachedir: .pytest_cache
rootdir: $REGENDOC_TMPDIR, inifile:
collecting ... collected 1 item
Expand All @@ -77,7 +77,7 @@ You can also select on the class::

$ pytest -v test_server.py::TestClass
=========================== test session starts ============================
platform linux -- Python 3.x.y, pytest-3.x.y, py-1.x.y, pluggy-0.x.y -- $PYTHON_PREFIX/bin/python3.6
platform linux -- Python 3.x.y, pytest-3.x.y, py-1.x.y, pluggy-0.x.y -- $PYTHON_PREFIX/bin/python
cachedir: .pytest_cache
rootdir: $REGENDOC_TMPDIR, inifile:
collecting ... collected 1 item
Expand All @@ -90,7 +90,7 @@ Or select multiple nodes::

$ pytest -v test_server.py::TestClass test_server.py::test_send_http
=========================== test session starts ============================
platform linux -- Python 3.x.y, pytest-3.x.y, py-1.x.y, pluggy-0.x.y -- $PYTHON_PREFIX/bin/python3.6
platform linux -- Python 3.x.y, pytest-3.x.y, py-1.x.y, pluggy-0.x.y -- $PYTHON_PREFIX/bin/python
cachedir: .pytest_cache
rootdir: $REGENDOC_TMPDIR, inifile:
collecting ... collected 2 items
Expand Down Expand Up @@ -128,7 +128,7 @@ select tests based on their names::

$ pytest -v -k http # running with the above defined example module
=========================== test session starts ============================
platform linux -- Python 3.x.y, pytest-3.x.y, py-1.x.y, pluggy-0.x.y -- $PYTHON_PREFIX/bin/python3.6
platform linux -- Python 3.x.y, pytest-3.x.y, py-1.x.y, pluggy-0.x.y -- $PYTHON_PREFIX/bin/python
cachedir: .pytest_cache
rootdir: $REGENDOC_TMPDIR, inifile:
collecting ... collected 4 items / 3 deselected
Expand All @@ -141,7 +141,7 @@ And you can also run all tests except the ones that match the keyword::

$ pytest -k "not send_http" -v
=========================== test session starts ============================
platform linux -- Python 3.x.y, pytest-3.x.y, py-1.x.y, pluggy-0.x.y -- $PYTHON_PREFIX/bin/python3.6
platform linux -- Python 3.x.y, pytest-3.x.y, py-1.x.y, pluggy-0.x.y -- $PYTHON_PREFIX/bin/python
cachedir: .pytest_cache
rootdir: $REGENDOC_TMPDIR, inifile:
collecting ... collected 4 items / 1 deselected
Expand All @@ -156,7 +156,7 @@ Or to select "http" and "quick" tests::

$ pytest -k "http or quick" -v
=========================== test session starts ============================
platform linux -- Python 3.x.y, pytest-3.x.y, py-1.x.y, pluggy-0.x.y -- $PYTHON_PREFIX/bin/python3.6
platform linux -- Python 3.x.y, pytest-3.x.y, py-1.x.y, pluggy-0.x.y -- $PYTHON_PREFIX/bin/python
cachedir: .pytest_cache
rootdir: $REGENDOC_TMPDIR, inifile:
collecting ... collected 4 items / 2 deselected
Expand Down
2 changes: 1 addition & 1 deletion doc/en/example/nonpython.rst
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ consulted when reporting in ``verbose`` mode::

nonpython $ pytest -v
=========================== test session starts ============================
platform linux -- Python 3.x.y, pytest-3.x.y, py-1.x.y, pluggy-0.x.y -- $PYTHON_PREFIX/bin/python3.6
platform linux -- Python 3.x.y, pytest-3.x.y, py-1.x.y, pluggy-0.x.y -- $PYTHON_PREFIX/bin/python
cachedir: .pytest_cache
rootdir: $REGENDOC_TMPDIR/nonpython, inifile:
collecting ... collected 2 items
Expand Down
7 changes: 3 additions & 4 deletions doc/en/example/parametrize.rst
Original file line number Diff line number Diff line change
Expand Up @@ -411,11 +411,10 @@ is to be run with different sets of arguments for its three arguments:
Running it results in some skips if we don't have all the python interpreters installed and otherwise runs all combinations (5 interpreters times 5 interpreters times 3 objects to serialize/deserialize)::

. $ pytest -rs -q multipython.py
...ssssssssssssssssssssssss [100%]
...sss...sssssssss...sss... [100%]
========================= short test summary info ==========================
SKIP [12] $REGENDOC_TMPDIR/CWD/multipython.py:29: 'python3.4' not found
SKIP [12] $REGENDOC_TMPDIR/CWD/multipython.py:29: 'python3.5' not found
3 passed, 24 skipped in 0.12 seconds
SKIP [15] $REGENDOC_TMPDIR/CWD/multipython.py:29: 'python3.4' not found
12 passed, 15 skipped in 0.12 seconds

Indirect parametrization of optional implementations/imports
--------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion doc/en/example/simple.rst
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ which will add info only when run with "--v"::

$ pytest -v
=========================== test session starts ============================
platform linux -- Python 3.x.y, pytest-3.x.y, py-1.x.y, pluggy-0.x.y -- $PYTHON_PREFIX/bin/python3.6
platform linux -- Python 3.x.y, pytest-3.x.y, py-1.x.y, pluggy-0.x.y -- $PYTHON_PREFIX/bin/python
cachedir: .pytest_cache
info1: did you know that ...
did you?
Expand Down
7 changes: 4 additions & 3 deletions doc/en/fixture.rst
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ to cause the decorated ``smtp_connection`` fixture function to only be invoked
once per test *module* (the default is to invoke once per test *function*).
Multiple test functions in a test module will thus
each receive the same ``smtp_connection`` fixture instance, thus saving time.
Possible values for ``scope`` are: ``function``, ``class``, ``module``, ``package`` or ``session``.

The next example puts the fixture function into a separate ``conftest.py`` file
so that tests from multiple test modules in the directory can
Expand Down Expand Up @@ -726,7 +727,7 @@ Running this test will *skip* the invocation of ``data_set`` with value ``2``::

$ pytest test_fixture_marks.py -v
=========================== test session starts ============================
platform linux -- Python 3.x.y, pytest-3.x.y, py-1.x.y, pluggy-0.x.y -- $PYTHON_PREFIX/bin/python3.6
platform linux -- Python 3.x.y, pytest-3.x.y, py-1.x.y, pluggy-0.x.y -- $PYTHON_PREFIX/bin/python
cachedir: .pytest_cache
rootdir: $REGENDOC_TMPDIR, inifile:
collecting ... collected 3 items
Expand Down Expand Up @@ -769,7 +770,7 @@ Here we declare an ``app`` fixture which receives the previously defined

$ pytest -v test_appsetup.py
=========================== test session starts ============================
platform linux -- Python 3.x.y, pytest-3.x.y, py-1.x.y, pluggy-0.x.y -- $PYTHON_PREFIX/bin/python3.6
platform linux -- Python 3.x.y, pytest-3.x.y, py-1.x.y, pluggy-0.x.y -- $PYTHON_PREFIX/bin/python
cachedir: .pytest_cache
rootdir: $REGENDOC_TMPDIR, inifile:
collecting ... collected 2 items
Expand Down Expand Up @@ -838,7 +839,7 @@ Let's run the tests in verbose mode and with looking at the print-output::

$ pytest -v -s test_module.py
=========================== test session starts ============================
platform linux -- Python 3.x.y, pytest-3.x.y, py-1.x.y, pluggy-0.x.y -- $PYTHON_PREFIX/bin/python3.6
platform linux -- Python 3.x.y, pytest-3.x.y, py-1.x.y, pluggy-0.x.y -- $PYTHON_PREFIX/bin/python
cachedir: .pytest_cache
rootdir: $REGENDOC_TMPDIR, inifile:
collecting ... collected 8 items
Expand Down
2 changes: 1 addition & 1 deletion doc/en/usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ Pytest supports the use of ``breakpoint()`` with the following behaviours:

- When ``breakpoint()`` is called and ``PYTHONBREAKPOINT`` is set to the default value, pytest will use the custom internal PDB trace UI instead of the system default ``Pdb``.
- When tests are complete, the system will default back to the system ``Pdb`` trace UI.
- If ``--pdb`` is called on execution of pytest, the custom internal Pdb trace UI is used on ``bothbreakpoint()`` and failed tests/unhandled exceptions.
- If ``--pdb`` is called on execution of pytest, the custom internal Pdb trace UI is used on both ``breakpoint()`` and failed tests/unhandled exceptions.
- If ``--pdbcls`` is used, the custom class debugger will be executed when a test fails (as expected within existing behaviour), but also when ``breakpoint()`` is called from within a test, the custom class debugger will be instantiated.

.. _durations:
Expand Down
20 changes: 10 additions & 10 deletions src/_pytest/assertion/rewrite.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,17 +269,17 @@ def _warn_already_imported(self, name):
)

def load_module(self, name):
# If there is an existing module object named 'fullname' in
# sys.modules, the loader must use that existing module. (Otherwise,
# the reload() builtin will not work correctly.)
if name in sys.modules:
return sys.modules[name]

co, pyc = self.modules.pop(name)
# I wish I could just call imp.load_compiled here, but __file__ has to
# be set properly. In Python 3.2+, this all would be handled correctly
# by load_compiled.
mod = sys.modules[name] = imp.new_module(name)
if name in sys.modules:
# If there is an existing module object named 'fullname' in
# sys.modules, the loader must use that existing module. (Otherwise,
# the reload() builtin will not work correctly.)
mod = sys.modules[name]
else:
# I wish I could just call imp.load_compiled here, but __file__ has to
# be set properly. In Python 3.2+, this all would be handled correctly
# by load_compiled.
mod = sys.modules[name] = imp.new_module(name)
try:
mod.__file__ = co.co_filename
# Normally, this attribute is 3.2+.
Expand Down
7 changes: 6 additions & 1 deletion src/_pytest/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,7 @@ def _set_initial_conftests(self, namespace):
else None
)
self._noconftest = namespace.noconftest
self._using_pyargs = namespace.pyargs
testpaths = namespace.file_or_dir
foundanchor = False
for path in testpaths:
Expand Down Expand Up @@ -416,7 +417,11 @@ def _importconftest(self, conftestpath):
_ensure_removed_sysmodule(conftestpath.purebasename)
try:
mod = conftestpath.pyimport()
if hasattr(mod, "pytest_plugins") and self._configured:
if (
hasattr(mod, "pytest_plugins")
and self._configured
and not self._using_pyargs
):
from _pytest.deprecated import (
PYTEST_PLUGINS_FROM_NON_TOP_LEVEL_CONFTEST
)
Expand Down
3 changes: 3 additions & 0 deletions src/_pytest/hookspec.py
Original file line number Diff line number Diff line change
Expand Up @@ -562,6 +562,9 @@ def pytest_warning_captured(warning_message, when, item):
* ``"runtest"``: during test execution.

:param pytest.Item|None item:
**DEPRECATED**: This parameter is incompatible with ``pytest-xdist``, and will always receive ``None``
in a future release.

The item being executed if ``when`` is ``"runtest"``, otherwise ``None``.
"""

Expand Down
5 changes: 4 additions & 1 deletion src/_pytest/mark/legacy.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,10 @@ def __getitem__(self, subname):

def matchmark(colitem, markexpr):
"""Tries to match on any marker names, attached to the given colitem."""
return eval(markexpr, {}, MarkMapping.from_item(colitem))
try:
return eval(markexpr, {}, MarkMapping.from_item(colitem))
except SyntaxError as e:
raise SyntaxError(str(e) + "\nMarker expression must be valid Python!")


def matchkeyword(colitem, keywordexpr):
Expand Down
Loading