Skip to content

@pytest.mark.parameterize gives misleading error messages  #39

Description

@edschofield

The following code fails with a misleading error message:

%%run_pytest[clean]
import pytest

@pytest.mark.parameterize('test_input,expected', [("3+5", 8)])
def test_eval(test_input, expected):
    assert eval(test_input) == expected

The error message is:

E                                                                        [100%]
==================================== ERRORS ====================================
________________ ERROR at setup of test_temperature_conversion _________________
file <ipython-input-22-dcba670f399e>, line 3
  @pytest.mark.parameterize("test_input,expected",
                            [
                                (100, 212)
                            ]
                           )
  def test_temperature_conversion(test_input, expected):
E       fixture 'test_input' not found
>       available fixtures: _session_faker, cache, capfd, capfdbinary, caplog, capsys, capsysbinary, cov, dash_br, dash_duo, dash_process_server, dash_thread_server, dashr, dashr_server, doctest_namespace, faker, monkeypatch, no_cover, pytestconfig, record_property, record_testsuite_property, record_xml_attribute, recwarn, tmp_path, tmp_path_factory, tmpdir, tmpdir_factory
>       use 'pytest --fixtures [testpath]' for help on them.

The error message is misleading because the cause is actually that parameterize has a different spelling to the parametrize spelling expected by pytest.

This is an easy mistake to make and, with the above error, it can be difficult to understand how to solve the problem. According to various dictionaries (e.g. https://www.merriam-webster.com/dictionary/parameterize), the verbs "parameterize" and "parametrize" are variants. A quick Google search turns up 1.97 million hits for "parameterize" versus 763,000 hits for "parametrize".

For reference, using pytest by itself (without ipytest) gives a much more useful error message:

test_eval.py:3: in <module>
    @pytest.mark.parameterize('test_input,expected', [("3+5", 8)])
E   Failed: Unknown 'parameterize' mark, did you mean 'parametrize'?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions