wonderwordsmodule icon indicating copy to clipboard operation
wonderwordsmodule copied to clipboard

`open_text` deprecation warning

Open quadespresso opened this issue 2 years ago • 2 comments

Describe the bug A clear and concise description of what the bug is.

Hit this while running pytest with this module:

../../.venv/lib/python3.11/site-packages/wonderwords/random_word.py:66
../../.venv/lib/python3.11/site-packages/wonderwords/random_word.py:66
../../.venv/lib/python3.11/site-packages/wonderwords/random_word.py:66
../../.venv/lib/python3.11/site-packages/wonderwords/random_word.py:66
  /home/jimc/proj/.venv/lib/python3.11/site-packages/wonderwords/random_word.py:66: DeprecationWarning: open_text is deprecated. Use files() instead. Refer to https://importlib-resources.readthedocs.io/en/latest/using.html#migrating-from-legacy for migration advice.
    words = pkg_resources.open_text(assets, word_file).readlines()

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html

To Reproduce Steps to reproduce the behavior:

  1. Go to '...'
  2. Click on '....'
  3. Scroll down to '....'
  4. See error

Create a simple pytest example such as this:

import pytest
from wonderwords import RandomWord

@pytest.fixture(scope="module")
def random_word_pair():
    """Return a noun/adjective pair of random words"""
    w = RandomWord()
    noun = w.word(include_categories=["noun"])
    adjective = w.word(include_categories=["adjective"])
    return noun, adjective

then run it:

❯ pytest simpletest.py
=============================================================================================== test session starts ===============================================================================================
platform linux -- Python 3.11.6, pytest-7.4.3, pluggy-1.3.0
rootdir: /home/jimc/testing
collected 0 items                                                                                                                                                                                                 

================================================================================================ warnings summary =================================================================================================
.venv/lib/python3.11/site-packages/wonderwords/random_word.py:66
.venv/lib/python3.11/site-packages/wonderwords/random_word.py:66
.venv/lib/python3.11/site-packages/wonderwords/random_word.py:66
.venv/lib/python3.11/site-packages/wonderwords/random_word.py:66
  /home/jimc/testing/.venv/lib/python3.11/site-packages/wonderwords/random_word.py:66: DeprecationWarning: open_text is deprecated. Use files() instead. Refer to https://importlib-resources.readthedocs.io/en/latest/using.html#migrating-from-legacy for migration advice.
    words = pkg_resources.open_text(assets, word_file).readlines()

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
=============================================================================================== 4 warnings in 0.00s ===============================================================================================

Expected behavior A clear and concise description of what you expected to happen.

No deprecation warnings pertaining to open_text while running pytest.

Screenshots If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • OS: [e.g. iOS]
  • Browser [e.g. chrome, safari]
  • Version [e.g. 22]

Smartphone (please complete the following information):

  • Device: [e.g. iPhone6]
  • OS: [e.g. iOS8.1]
  • Browser [e.g. stock browser, safari]
  • Version [e.g. 22]

Additional context Add any other context about the problem here.

quadespresso avatar Dec 16 '23 00:12 quadespresso

I can confirm I'm seeing the same behaviour in pytest as well.

mmb-davidsmith avatar Jan 12 '24 17:01 mmb-davidsmith

Yep. Docs say it's deprecated starting with 3.11. Will update that

mrmaxguns avatar Apr 09 '24 16:04 mrmaxguns