2

I am using openpyxl for parsing .xlsm files, and pytest for testing.

When I open a file, I get the:
OpenPyxl -> UserWarning: Data Validation extension is not supported and will be removed

That is not really a problem bcs. program works and I can't change the .xlsm file to fix that.

But... When I run pytest with something like:

def test_wrong_file_format():  
    assert check_excel(open_excel('file.xlsm')) == True

I will get the warning i mentioned altought check_excel(open_excel('file.xlsm')) returns True and the test should suceed...

Is there a nice way to tell the pytest that "It's not a bug it's a feature" and tests should pass even when they get this warning?

Is there other way than using something like:

with pytest.warns(UserWarning):
    warnings.warn("my warning", UserWarning)

Thank you,
Tom

Tom91
  • 23
  • 4
  • `pytest -W ignore::UserWarning`. Or persist it in `pytest.cfg` to not to enter it each time: `filterwarnings = ignore::UserWarning`. – hoefling Nov 22 '18 at 16:39

1 Answers1

1

According to the official documentation (pytest), @pytest.mark.filterwarnings is the right approach. Just choose the correct params, for example:

@pytest.mark.filterwarnings('ignore::UserWarning')
Aleksey
  • 1,299
  • 9
  • 13
  • 2
    Thank you, it works. the correct syntax is: `@pytest.mark.filterwarnings('ignore::UserWarning')` – Tom91 Nov 26 '18 at 09:29