0

I was following this answer about how to add custom arguments to pytest in order to skip tests with the custom marker. It works, but I can't seem to customize it to use a short version of the flag.

I've added these functions to my conftest.py:

def pytest_addoption(parser):
    parser.addoption("-fs", dest='full_suite', action="store_true",
        help="Run the full test suite. Includes tests marked with the mark.full_suite flag")


def pytest_runtest_setup(item):
    if 'full_suite' in item.keywords and not item.config.getoption("-fs"):
        pytest.skip("You need the -fs option to run this test")

And then I write this test:

@pytest.mark.full_suite
def test_something():
    assert True

If I use the long option, for example, --fs, rather than -fs, it will work, and dest will be assigned to fs. With the short option, I'm apparently required to supply the dest keyword. But I did this, I added dest='full_suite. Despite that, I get this error:

....
 self.option_id = str(option)
  File "/home/jokea/Carbonspace/cs-landsat-sentinel/.python3.8_env/lib/python3.8/site-packages/_pytest/config/argparsing.py", line 326, in __repr__
    args += ["dest: " + repr(self.dest)]
AttributeError: 'Argument' object has no attribute 'dest'

What am I missing?

John Kealy
  • 1,503
  • 1
  • 13
  • 32
  • 1
    This may not be possible, have a look at [this answer](https://stackoverflow.com/a/67244345/12480730). – MrBean Bremen May 17 '22 at 10:02
  • Ah cool, thanks. In my case that's actually a solution; I can just use an upper case letter for the flag, instead of a lowercase one. – John Kealy May 17 '22 at 11:11

0 Answers0