mirror of
https://github.com/beetbox/beets.git
synced 2025-12-15 13:07:09 +01:00
confit: Improve deprecation warning
Show the actual origin of the import statement, cf. #4024
This commit is contained in:
parent
51e478ed1d
commit
cc8c3529fb
2 changed files with 22 additions and 1 deletions
|
|
@ -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():
|
||||
|
|
|
|||
|
|
@ -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__)
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue