pytest-dev / pytest-dev/pytest
--fixtures and --markers are broken when there's a required option added in pytest_addoption()
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 14.5k
- Forks
- 3.4k
- Avg merge
- 2d 9h
- Merged PRs (30d)
- 35
Description
Similar to https://github.com/pytest-dev/pytest/issues/1999
When you add a required option in pytest_addoption the --fixtures and --markers arguments cannot be used without specifying the required options. This was fixed for --help in https://github.com/pytest-dev/pytest/pull/2458.
Example
conftest.py
import pytest
def pytest_addoption(parser):
parser.addoption("--please-work", action="store_true", required=True)
@pytest.fixture
def spam():
return "spam"
Output
fixtures_required> pytest
usage: pytest [options] [file_or_dir] [file_or_dir] [...]
pytest: error: argument --please-work is required
>pytest --help
usage: pytest [options] [file_or_dir] [file_or_dir] [...]
positional arguments:
file_or_dir
general:
-k EXPRESSION only run tests which match the given substring
expression. An expression is a python evaluatable
expression where all names are substring-matched
against test names and their parent classes. Example:
-k 'test_method or test_other' matches all test
functions and classes whose name contains
'test_method' or 'test_other', while -k 'not
test_method' matches those that don't contain
'test_method' in their names. Additionally keywords
are matched to classes and functions containing extra
names in their 'extra_keyword_matches' set, as well as
functions which have names assigned directly to them.
<snip>
to see available markers type: pytest --markers
to see available fixtures type: pytest --fixtures
(shown according to specified file_or_dir or current dir if not specified)
fixtures_required>pytest --fixtures
usage: pytest [options] [file_or_dir] [file_or_dir] [...]
pytest: error: argument --please-work is required
fixtures_required>pytest --markers
usage: pytest [options] [file_or_dir] [file_or_dir] [...]
pytest: error: argument --please-work is required
Versions
Windows 10.0.16299.125 x64
Package Version Location
---------- --------------------- -------------------------
appdirs 1.4.3
attrs 17.3.0
colorama 0.3.9
funcsigs 1.0.2
packaging 16.8
pip 9.0.1
pluggy 0.6.0
py 1.5.2
pyparsing 2.2.0
pytest 3.3.2.dev45+g370daf04
setuptools 38.2.4
six 1.11.0
tox 2.9.1
virtualenv 15.1.0
wheel 0.30.0
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the example with a conftest.py defining a required pytest_addoption option, then compare the behavior of --fixtures and --markers with --help. Trace the pytest command-line handling for these options and add regression coverage showing they work without requiring unrelated options; done means both commands list their requested information successfully.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- cli, testing
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100