question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Misleading error message when parameters are missing in the parametrize but presented in the test function

See original GitHub issue
  • a detailed description of the bug or problem you are having
  • output of pip list from the virtual environment you are using
  • pytest and operating system versions
  • minimal example if possible

I’m using pytest version 6.2.4. Say we have the following function and a corresponding test function:

# ./add.py
def add(n1, n2):
  return n1 + n2

# ./test_add.py
@pytest.mark.parametrize(
  "arg1, expected_answer",
  [pytest.param(2, 3, 5)]
)
def test_add(arg1, arg2, expected_answer):
  assert add(arg1, arg2) == expected_answer

Running pytest ./test_add.py::test_add logs the following error message:

ERROR: not found: ./test_add.py::test_add
(no name './test_add.py::test_add' in any of [<Module test_add.py>])

But actually it fails because arg2 is not presented in the parametrize decorator. Similar issue when the argument name is wrong.

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:10 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
jekwattcommented, Jul 16, 2022

I was able to duplicate the error. Working to fix the error message.

2reactions
The-Compilercommented, Jul 8, 2022

This is the full output:

============================= test session starts ==============================
collected 0 items / 1 error                                                    

==================================== ERRORS ====================================
_________________________ ERROR collecting test_add.py _________________________
test_add.py::test_add: in "parametrize" the number of names (2):
  ['arg1', 'expected_answer']
must be equal to the number of values (3):
  (2, 3, 5)
=========================== short test summary info ============================
ERROR test_add.py
=============================== 1 error in 0.04s ===============================
ERROR: not found: /home/florian/tmp/test_add.py::test_add
(no name '/home/florian/tmp/test_add.py::test_add' in any of [<Module test_add.py>])

seems quite clear from that what the error is, no?

Read more comments on GitHub >

github_iconTop Results From Across the Web

unit testing with pytest parametrize - python - Stack Overflow
parametrize on unittest.TestCase methods . PyTest has no way to pass in the parameter. Just do: @pytest.mark.parametrize( ...
Read more >
Parametrizing tests — pytest documentation
Generating parameters combinations, depending on command line¶. Let's say we want to execute a test with different computation parameters and the parameter ......
Read more >
Advanced googletest Topics
This document will show you more assertions as well as how to construct complex failure messages, propagate fatal failures, reuse and speed up...
Read more >
Parameterize BDD Tests | TestComplete Documentation
Let's create a BDD scenario for this task. In BDD tests, you parameterize test steps, not scenarios or features. That is, you set...
Read more >
JUnit 5 Tutorial: Writing Parameterized Tests - Petri Kainulainen
This annotation identifies parameterized test methods. Provide the method parameters which are passed to our test method. Because our test ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found