How to tell py.test to skip certain directories?

后端 未结 8 1388
情话喂你
情话喂你 2021-02-06 20:07

I tried to use the norecursedirs option inside setup.cfg to tell py.test not to collect tests from certain directories but it seems it does ignore it.

[tool:pyte         


        
相关标签:
8条回答
  • 2021-02-06 20:27

    If you are using setup.cfg, you have to use [tool:pytest] as per http://doc.pytest.org/en/latest/example/pythoncollection.html

    # content of pytest.ini
    # can also be defined in tox.ini or setup.cfg file, although the section
    # name in setup.cfg files should be "tool:pytest"

    0 讨论(0)
  • 2021-02-06 20:31

    You can use

    py.test -k 'not third'
    

    that excludes all 'third' directory contents.

    0 讨论(0)
  • 2021-02-06 20:31

    To use pytest.ini (which is recommended, unless you're using tox in which case tox.ini would make sense), call pytest with pytest -c pytest.ini.

    In order to prevent my sample not_me_1.py and not_me_2.py from being tested or linted, my pytest.ini is as follows:

    [pytest]
    addopts = --ignore-glob=not_me_*
    
    [pycodestyle]
    ignore = not_me_* ALL
    
    
    0 讨论(0)
  • 2021-02-06 20:39

    norecursedirs should work. Check whether you have a pytest.ini or other setup.cfg files. How are you invoking py.test?

    0 讨论(0)
  • 2021-02-06 20:45

    If you have several directories with different parents you can specify different --ignore parameters:

    py.test --ignore=somedir --ignore=otherdir --ignore=etcdir

    • new option: --ignore will prevent specified path from collection.
      Can be specified multiple times.
    0 讨论(0)
  • 2021-02-06 20:47

    py.test --ignore=somedir worked for me

    0 讨论(0)
提交回复
热议问题