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.

test ids with `/`s cannot be selected with `-k`

See original GitHub issue

By default pytest 6.2.2 parametrize does user arguments to generate IDs, but some of these ids cannot be used with -k option because you endup with errors like unexpected character "/" when trying to do so.

The solution for this bug is to assure that auto-generated IDs are sanitized so they can be used with -k option.

Example:

@pytest.mark.parametrize(
    ('path', 'kind'),
    (
        ("foo/playbook.yml", "playbook"),
    ),
)
def test_auto_detect(path: str, kind: FileType) -> None:
   ...

As you can see the first parameter includes a slash, and for good reasons. It is far from practical to have to add custom “ids” for all of these, as you can have LOTS of them.

There is another annoyance related to the -k selecting for parameterized tests, is the fact that square braces [] have special meanings for some shells and in order to use it you must remember to quote the strings. It would be much easier if the display and selecting of parametrized tests would use only shell-safe format, so we can easily copy/paste a failed test in run it. For example I think that using colon would be safe and arguably even easier to read: test_name:param1:param2.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
bluetechcommented, Oct 29, 2021

Let’s allow / in -k expressions. I don’t see it being useful as an operator, and if it’s allowed in nodeids, then it should be allowed in -k.

Here 25c65616f4455ac78be1027c2fb4debef827c4e6 is a commit which allowed \ - adding / would be very similar. PRs welcome!

1reaction
asottilecommented, Mar 7, 2021

updated the title to more accurately reflect that the ids aren’t invalid, they just can’t be selected using -k

Read more comments on GitHub >

github_iconTop Results From Across the Web

Working with custom markers — pytest documentation
You can provide one or more node IDs as positional arguments to select only specified tests. This makes it easy to select tests...
Read more >
java - What does a "Cannot find symbol" or "Cannot resolve ...
A "Cannot find symbol" error means that the compiler cannot do this. ... with the dependencies; e.g. left out a dependency, or selected...
Read more >
Helpful resources for test-takers - Pearson VUE
Explore helpful resources, like exam prep materials and FAQs, as you prepare for your computer-based certification or licensure exam.
Read more >
Cannot Read Property of Undefined in JavaScript - Rollbar
TypeError: Cannot read property of undefined occurs when a property is read or a function is called on an undefined variable.
Read more >
How to Register for a Praxis Test - ETS
Select a step to learn more about your Praxis ® journey. Plan Your Test ... Check your state testing requirements to see which...
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