0

I am trying to setup the pytest.ini configuration file such that any benchmark test runs with the "--benchmark-autosave" option as on and other tests do not.

I have tried adding the option in the ini file as follows...

[pytest]
addopts = --benchmark-autosave

However it runs this option with every tests resulting in PytestBenchmarkWarning warnings. I am wondering if there is a way just to run this option on pytests that have benchmark used.

I have looked into...

[pytest]
addopts = --benchmark-autosave
filterwarnings = 
     ignore::PytestBenchmarkWarning

However, I get this error:

INTERNALERROR> warnings. OptionError: unknown warning category: 'PytestBenchmarkWarning'

If I have the tests as follows test_a.py

import a
import pytest

def test_a(benchmark):
     benchmark(a.func)

test_b.py

import b
import pytest

def test_b():
     b.func()

pytest.ini

[pytest]
addopts = --benchmark-autosave
filterwarnings = 
     ignore::PytestBenchmarkWarning

with file structure:

my_project/src/a.py
my_project/src/b.py
my_project/test/test_a.py
my_project/test/test_b.py
my_project/pytest.ini

Under a terminal:

cd my_project
pytest test/
Interlooper
  • 494
  • 2
  • 5
  • 14
  • Why don't you show the warning? I don't get any warnings with latest package versions, try bumping package and deps to latest version with `pip install --upgrade --force-reinstall pytest-benchmark` – hoefling Jul 05 '19 at 20:29
  • 3
    As for the warnings filter, you need to provide full import name of the warning class (so `pytest` can actually import the class). `ignore::pytest_benchmark.logger.PytestBenchmarkWarning` should work. – hoefling Jul 05 '19 at 20:31
  • Ahh yeah your right, I should have said in my post, under terminal if you ran `pytest test/b.py` it would give a warning when I wouldn't want it to. – Interlooper Jul 05 '19 at 20:34
  • Then it's code in `b.py` that is raising the warning, not your test code. – hoefling Jul 06 '19 at 09:16

0 Answers0