Skip to content
Snippets Groups Projects
Commit 7eb87787 authored by Alan De Smet's avatar Alan De Smet
Browse files

Suppress some warnings during doctest

These are warnings that are normally suppressed, but unittest turns them
on. They're not helpful because it's complaining I'm not .close()ing
files, but adding that would make the documention less clear. So,
suppres them.
parent 7df9df69
Branches
No related tags found
No related merge requests found
......@@ -668,6 +668,21 @@ class DownloaderTests(DTestCase):
self.assertMockFile(outdir+"/avhrr-only-v2.20170105.nc")
def add_module_doctest(tests, module, context):
import warnings
import doctest
def suppress(module):
for mod in (module, 'doctest'):
warnings.filterwarnings("ignore",
message= r'unclosed file <_io.TextIOWrapper',
category=ResourceWarning,
module=mod+"$")
tests_before = tests.countTestCases()
tests.addTests(doctest.DocTestSuite(setUp=lambda x:suppress(module), globs=context))
tests_after = tests.countTestCases()
if tests_before >= tests_after:
raise Exception(f"Had {tests_before}, added doctests for {module.__name__}, then had {tests_after}, which is not more. Seems bad.")
def load_tests(loader, tests, ignore):
import doctest
......@@ -712,25 +727,17 @@ def load_tests(loader, tests, ignore):
'd': sst,
}
print("start", tests.countTestCases())
tests.addTests(doctest.DocTestSuite(globs=context))
print("self",tests.countTestCases())
tests.addTests(doctest.DocTestSuite(csppfetch, globs=context))
print("csppfetch", tests.countTestCases())
add_module_doctest(tests, csppfetch, context)
import csppfetch.exclusivelockfile as exclusivelockfile
import csppfetch.daterange as daterange
tests.addTests(doctest.DocTestSuite(exclusivelockfile, globs=context))
print("exclusivelockfile", tests.countTestCases())
tests.addTests(doctest.DocTestSuite(daterange, globs=context))
print("daterange", tests.countTestCases())
add_module_doctest(tests, exclusivelockfile, context)
tests.addTests(doctest.DocTestSuite(csppfetch.timelimit, globs=context))
print("timelimit", tests.countTestCases())
import csppfetch.daterange as daterange
add_module_doctest(tests, daterange, context)
add_module_doctest(tests, csppfetch.timelimit, context)
return tests
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment