pytest-dev / pytest-dev/pytest

[minor QoL] allow specifying -k multiple times

Open
#12,084 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

topic: selection type: proposal
Dominant language
Python
Stars
14.5k
Forks
3.4k
Avg merge
2d 9h
Merged PRs (30d)
35

Description

What's the problem this feature will solve?

In projects with lots of parametrized tests across versions, behaviour, etc - or with lots of tests in general - I like to progressively exclude tests while working on features unrelated to those tests to save time on running the test suite. That means I can rack up a series of selected names, especially if working iteratively. Example invocation from my CLI history: pytest -k 'asyncio and normal and noautofix' --no-cov -v -n auto.
Stacking on qualifiers currently requires going back and modifying this one text string, and require quoting and the extra and, instead of being able to quickly step back in history and smack on an extra -k.
Currently doing pytest -k asyncio -k normal will throw out the first -k and resolve as pytest -k normal.

Describe the solution you'd like

-k to stack, with and, when specified multiple times [on the command line].

Alternative Solutions

Add another flag that achieves the above, such as not to break any current behaviour which might rely on overriding it.

I could also write a CLI function that preparses flags before passing on to pytest proper, in case you deem this too niche to bother with. Relying on plugins, or adding a custom flag to conftest.py would be a no-go as I use this in several different projects and is not something I'd want to commit to random repositories.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating pytest's command-line handling for repeated -k options and the existing tests covering -k. Add coverage for multiple -k arguments combined with and, preserving current single-value behavior, then run the relevant command-line test suite to verify both cases.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
cli, testing-qa
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.