Skip to content

Commit

Permalink
Prefer caplog to mocking the logging interface.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaraco committed Oct 5, 2022
1 parent d0bfcdb commit 45295fc
Showing 1 changed file with 5 additions and 11 deletions.
16 changes: 5 additions & 11 deletions distutils/tests/test_build_py.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import os
import sys
import unittest.mock as mock

import pytest

Expand Down Expand Up @@ -167,8 +166,7 @@ def test_dont_write_bytecode(self, logs):

assert 'byte-compiling is disabled' in logs.render()[0]

@mock.patch("distutils.command.build_py.log.warn")
def test_namespace_package_does_not_warn(self, log_warn):
def test_namespace_package_does_not_warn(self, caplog):
"""
Originally distutils implementation did not account for PEP 420
and included warns for package directories that did not contain
Expand All @@ -182,13 +180,6 @@ def test_namespace_package_does_not_warn(self, log_warn):
os.makedirs("ns/pkg")
open("ns/pkg/module.py", "w").close()

# Set up a trap if the undesirable effect is observed:
def _trap(msg, *args):
if "package init file" in msg and "not found" in msg:
raise AssertionError(f"Undesired warning: {msg!r} {args!r}")

log_warn.side_effect = _trap

# Configure the package:
attrs = {
"name": "ns.pkg",
Expand All @@ -206,4 +197,7 @@ def _trap(msg, *args):
assert module_path.replace(os.sep, "/") == "ns/pkg/module.py"

cmd.run()
# Test should complete successfully with no exception

assert not any(
"package init file" in msg and "not found" in msg for msg in caplog.messages
)

0 comments on commit 45295fc

Please sign in to comment.