test ids with `/`s cannot be selected with `-k`
See original GitHub issueBy 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:
- Created 3 years ago
- Reactions:1
- Comments:6 (6 by maintainers)
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!updated the title to more accurately reflect that the ids aren’t invalid, they just can’t be selected using
-k