mirror of https://github.com/pypa/pip
add tests
This commit is contained in:
parent
9dabcffc80
commit
584d96bfe9
|
@ -197,10 +197,6 @@ def main(args=None):
|
|||
if args is None:
|
||||
args = sys.argv[1:]
|
||||
|
||||
# Enable our Deprecation Warnings
|
||||
for deprecation_warning in deprecation.DEPRECATIONS:
|
||||
warnings.simplefilter("default", deprecation_warning, append=True)
|
||||
|
||||
# Configure our deprecation warnings to be sent through loggers
|
||||
deprecation.install_warning_logger()
|
||||
|
||||
|
|
|
@ -27,11 +27,6 @@ class Python26DeprecationWarning(PipDeprecationWarning, Pending):
|
|||
pass
|
||||
|
||||
|
||||
DEPRECATIONS = [
|
||||
RemovedInPip9Warning, RemovedInPip10Warning, Python26DeprecationWarning
|
||||
]
|
||||
|
||||
|
||||
# Warnings <-> Logging Integration
|
||||
|
||||
|
||||
|
@ -71,6 +66,9 @@ def _showwarning(message, category, filename, lineno, file=None, line=None):
|
|||
|
||||
|
||||
def install_warning_logger():
|
||||
# Enable our Deprecation Warnings
|
||||
warnings.simplefilter("default", PipDeprecationWarning, append=True)
|
||||
|
||||
global _warnings_showwarning
|
||||
|
||||
if _warnings_showwarning is None:
|
||||
|
|
|
@ -0,0 +1,36 @@
|
|||
import pytest
|
||||
|
||||
PY26_WARNING = "Python 2.6 is no longer supported"
|
||||
|
||||
|
||||
@pytest.mark.skipif("sys.version_info >= (2,7)")
|
||||
def test_python26_options(script):
|
||||
result = script.run(
|
||||
'python', '-m', 'pip.__main__', 'list', expect_stderr=True,
|
||||
)
|
||||
assert PY26_WARNING in result.stderr
|
||||
result = script.run('python', '-W', 'ignore', '-m', 'pip.__main__', 'list')
|
||||
assert result.stderr == ''
|
||||
|
||||
|
||||
@pytest.mark.skipif("sys.version_info < (2,7)")
|
||||
def test_environ(script, tmpdir):
|
||||
"""$PYTHONWARNINGS was added in python2.7"""
|
||||
demo = tmpdir.join('warnings_demo.py')
|
||||
demo.write('''
|
||||
from pip.utils import deprecation
|
||||
deprecation.install_warning_logger()
|
||||
|
||||
from logging import basicConfig
|
||||
basicConfig()
|
||||
|
||||
from warnings import warn
|
||||
warn("deprecated!", deprecation.PipDeprecationWarning)
|
||||
''')
|
||||
|
||||
result = script.run('python', demo, expect_stderr=True)
|
||||
assert result.stderr == 'ERROR:pip.deprecations:DEPRECATION: deprecated!\n'
|
||||
|
||||
script.environ['PYTHONWARNINGS'] = 'ignore'
|
||||
result = script.run('python', demo)
|
||||
assert result.stderr == ''
|
Loading…
Reference in New Issue