Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions Lib/test/test_venv.py
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,9 @@ def do_test_with_pip(self, system_site_packages):
self.fail(msg.format(exc, details))
# Ensure pip is available in the virtual environment
envpy = os.path.join(os.path.realpath(self.env_dir), self.bindir, self.exe)
cmd = [envpy, '-Im', 'pip', '--version']
# Ignore DeprecationWarning since pip code is not part of Python
cmd = [envpy, '-W', 'ignore::DeprecationWarning', '-I',
'-m', 'pip', '--version']
p = subprocess.Popen(cmd, stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
out, err = p.communicate()
Expand All @@ -386,7 +388,8 @@ def do_test_with_pip(self, system_site_packages):
# http://bugs.python.org/issue19728
# Check the private uninstall command provided for the Windows
# installers works (at least in a virtual environment)
cmd = [envpy, '-Im', 'ensurepip._uninstall']
cmd = [envpy, '-W', 'ignore::DeprecationWarning', '-I',
'-m', 'ensurepip._uninstall']
with EnvironmentVarGuard() as envvars:
p = subprocess.Popen(cmd, stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
Expand Down
14 changes: 9 additions & 5 deletions Lib/warnings.py
Original file line number Diff line number Diff line change
Expand Up @@ -508,10 +508,13 @@ def _filters_mutated():
# Module initialization
_processoptions(sys.warnoptions)
if not _warnings_defaults:
silence = [ImportWarning, PendingDeprecationWarning]
silence.append(DeprecationWarning)
for cls in silence:
simplefilter("ignore", category=cls)
py_debug = hasattr(sys, 'gettotalrefcount')
if not py_debug:
silence = [ImportWarning, PendingDeprecationWarning]
silence.append(DeprecationWarning)
for cls in silence:
simplefilter("ignore", category=cls)

bytes_warning = sys.flags.bytes_warning
if bytes_warning > 1:
bytes_action = "error"
Expand All @@ -520,8 +523,9 @@ def _filters_mutated():
else:
bytes_action = "ignore"
simplefilter(bytes_action, category=BytesWarning, append=1)

# resource usage warnings are enabled by default in pydebug mode
if hasattr(sys, 'gettotalrefcount'):
if py_debug:
resource_action = "always"
else:
resource_action = "ignore"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
warnings: When Python is build is debug mode (``Py_DEBUG``),
:exc:`DeprecationWarning`, :exc:`PendingDeprecationWarning` and
:exc:`ImportWarning` warnings are now displayed by default.
7 changes: 7 additions & 0 deletions Python/_warnings.c
Original file line number Diff line number Diff line change
Expand Up @@ -1196,20 +1196,27 @@ create_filter(PyObject *category, const char *action)
static PyObject *
init_filters(void)
{
#ifndef Py_DEBUG
PyObject *filters = PyList_New(5);
#else
PyObject *filters = PyList_New(2);
#endif
unsigned int pos = 0; /* Post-incremented in each use. */
unsigned int x;
const char *bytes_action, *resource_action;

if (filters == NULL)
return NULL;

#ifndef Py_DEBUG
PyList_SET_ITEM(filters, pos++,
create_filter(PyExc_DeprecationWarning, "ignore"));
PyList_SET_ITEM(filters, pos++,
create_filter(PyExc_PendingDeprecationWarning, "ignore"));
PyList_SET_ITEM(filters, pos++,
create_filter(PyExc_ImportWarning, "ignore"));
#endif

if (Py_BytesWarningFlag > 1)
bytes_action = "error";
else if (Py_BytesWarningFlag)
Expand Down