Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit daa1503

Browse files
committed
filter py2.7 RuntimeWarnings for lazy import tests
1 parent 43fdfc0 commit daa1503

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

dateutil/test/test_imports.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,25 @@
11
import sys
22
import unittest
33
import pytest
4+
import six
45

56
MODULE_TYPE = type(sys)
7+
8+
9+
# Tests live in datetutil/test which cause a RuntimeWarning for Python2 builds.
10+
# But since we expect lazy imports tests to fail for Python < 3.7 we'll ignore those
11+
# warnings with this filter.
12+
if six.P2:
13+
filter_import_warning = pytest.mark.filterwarnings('RuntimeWarning')
14+
else:
15+
def filter_import_warning(f):
16+
return f
17+
618
@pytest.fixture(scope='function')
719
def clean_import():
820
""" Create a somewhat clean import base for lazy import tests """
921
du_modules = {mod_name: mod for mod_name, mod in sys.modules.items()
10-
if mod_name.startswith('dateutil')
11-
and not 'dateutil.test' in mod_name}
22+
if mod_name.startswith('dateutil')}
1223

1324
other_modules = {mod_name for mod_name in sys.modules
1425
if mod_name not in du_modules}
@@ -28,7 +39,7 @@ def clean_import():
2839
for mod_name, mod in du_modules.items():
2940
sys.modules[mod_name] = mod
3041

31-
42+
@filter_import_warning
3243
@pytest.mark.parametrize('module', ['easter', 'parser', 'relativedelta',
3344
'rrule', 'tz', 'utils', 'zoneinfo'])
3445
def test_lazy_import(clean_import, module):

0 commit comments

Comments
 (0)