Merge pull request #4263 from wisp3rwind/pr_better_deprecation_warning

confit: Improve deprecation warning
This commit is contained in:
Adrian Sampson 2022-02-02 10:38:46 -05:00 committed by GitHub
commit debbe4efa5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 1 deletions

View file

@ -16,7 +16,13 @@
import confuse
import warnings
warnings.warn("beets.util.confit is deprecated; use confuse instead")
warnings.warn(
"beets.util.confit is deprecated; use confuse instead",
# Show the location of the `import confit` statement as the warning's
# source, rather than this file, such that the offending module can be
# identified easily.
stacklevel=2,
)
# Import everything from the confuse module into this module.
for key, value in confuse.__dict__.items():

View file

@ -182,6 +182,21 @@ class PathTruncationTest(_common.TestCase):
self.assertEqual(p, 'abcde/f.ext')
class ConfitDeprecationTest(_common.TestCase):
def test_confit_deprecattion_warning_origin(self):
"""Test that importing `confit` raises a warning.
In addition, ensure that the warning originates from the actual
import statement, not the `confit` module.
"""
# See https://github.com/beetbox/beets/discussions/4024
with self.assertWarns(UserWarning) as w:
import beets.util.confit # noqa: F401
self.assertIn(__file__, w.filename)
self.assertNotIn("confit.py", w.filename)
def suite():
return unittest.TestLoader().loadTestsFromName(__name__)