From 6d9061b00a67369c587d1754bac7a3fc390e823d Mon Sep 17 00:00:00 2001 From: Chris Mayo Date: Fri, 2 Sep 2022 19:29:11 +0100 Subject: [PATCH] Ignore bs4 markup and XML parser warnings XMLParsedAsHTMLWarning: It looks like you're parsing an XML document using an HTML parser. MarkupResemblesLocatorWarning: The input looks more like a filename than markup. MarkupResemblesLocatorWarning: The input looks more like a URL than markup. --- linkcheck/htmlutil/htmlsoup.py | 16 ++++++++++++---- pytest.ini | 3 +++ 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/linkcheck/htmlutil/htmlsoup.py b/linkcheck/htmlutil/htmlsoup.py index 8819bc6c..d8af6a08 100644 --- a/linkcheck/htmlutil/htmlsoup.py +++ b/linkcheck/htmlutil/htmlsoup.py @@ -17,19 +17,27 @@ HTML parser implemented using Beautiful Soup and html.parser. """ -from warnings import filterwarnings +import warnings -filterwarnings( +warnings.filterwarnings( "ignore", message="The soupsieve package is not installed. CSS selectors cannot be used.", category=UserWarning, module="bs4", ) -from bs4 import BeautifulSoup +import bs4 + +warnings.simplefilter( + 'ignore', bs4.MarkupResemblesLocatorWarning +) + +warnings.simplefilter( + 'ignore', bs4.builder.XMLParsedAsHTMLWarning +) def make_soup(markup, from_encoding=None): - return BeautifulSoup( + return bs4.BeautifulSoup( markup, "html.parser", from_encoding=from_encoding, multi_valued_attributes=None ) diff --git a/pytest.ini b/pytest.ini index f78fcd79..9a495d43 100644 --- a/pytest.ini +++ b/pytest.ini @@ -1,3 +1,6 @@ [pytest] testpaths = tests addopts = -ra --tb=short +filterwarnings = + ignore::bs4.MarkupResemblesLocatorWarning + ignore::bs4.builder.XMLParsedAsHTMLWarning