pytest
pytest copied to clipboard
support an alternate syntax for "not" (as in `pytest -m "not stuff"`)
What's the problem this feature will solve?
Lots of CI systems heavily rely on bash or various bash scripts. And even tho we're in 2024, passing quotes into bash is still tricky. I would ask that an alternate way of specifying "not", such as :
these would be similar
poetry run pytest -m "not mymarker"
poetry run pytest -not-m mymarker
poetry run pytest -m not_mymarker
Describe the solution you'd like
basically an alternate syntax that would not require quotation marks to specify it
Alternative Solutions
Additional context
about 10 years ago there was such a syntax, it created numerous issues - now we have a regular language
and right to my point all of your proposals are incorrect applications of the short argument for thats invalid in any case
the syntax before was -marker and created a lot of trouble when composing arguments
imho its on ci systems to finally add save ways to invoke things,
im -1 on re-adding a mess just to avoid quotes as from personal experience the messes to avoid quotes where so far worse
I agree. All of your proposed syntaxes come with their own problems - except :marker maybe, but that is entirely non-obvious. I don't think it's a good idea to have yet another problematic and/or non-obvious way to do the same thing.
How is "passing quotes into bash still tricky"?
to be fair bash in yaml in ci with variable pass-over can sill turn into nightmares the moment one makes a variable quoting mistake as bash is demonstrably hostile to writing correct code in any non-trivial capacity
Seems like this could be handled by a plugin or a local conftest.py modification.
The example below doesn't handle fancy logic, but for simple marker deselection, it works fine.
Unless I'm missing some requirement.
# put this in conftest.py to avoid markers
# Example:
# `pytest --not foo` will deselect `foo` marked tests.
# `pytest --not foo bar` will deselect both `foo` and `bar` marked tests.
# etc.
def pytest_addoption(parser):
parser.addoption('--not', action='store', dest='not_markers', nargs='*',
help='markers to not run')
def pytest_collection_modifyitems(config, items):
not_markers = config.option.not_markers
if not_markers:
# just in case someone calls --not foo, bar
# strip out commas
not_markers = [m.strip(',') for m in not_markers]
selected_items = []
deselected_items = []
for item in items:
found_unwanted_marker = False
for avoid in not_markers:
if item.get_closest_marker(avoid):
found_unwanted_marker = True
if found_unwanted_marker:
deselected_items.append(item)
else:
selected_items.append(item)
config.hook.pytest_deselected(items=deselected_items)
items[:] = selected_items
I think I need this also, maybe I'll write a plugin
Bonus. pytest -m foo --not foo is a way to have 0 failures in your test suite.
This issue is stale because it has the status: needs information label and requested follow-up information was not provided for 14 days.
This issue was closed because it has the status: needs information label and follow-up information has not been provided for 7 days since being marked as stale.