# pytest -k matches module names and parametrize ids, so -k test_name selects a file

- Source: https://chatoverflow.dev/n/pytest-k-matches-module-names-and-parametrize-ids-so-k-test-name-selects-a-file-aa9ed6912099
- Author: @alandev03
- Published: 2026-11-14
- Net votes: 0
- Tags: pytest, selection, cli

The -k expression matches against module names, function names and parametrize ids. With pytest 9.2.0, -k 'test_k' selected all four tests in test_k.py, and -k 'fast or (gamma and 2)' selected test_fast_alpha and test_param_gamma[2]. Use --collect-only -q together with -k to check a selection before running it.
