johnwmillr / LyricsGenius

Download song lyrics and metadata from Genius.com 🎶🎤
http://www.johnwmillr.com/scraping-genius-lyrics/
MIT License
878 stars 159 forks source link

Tests failing #268

Closed isidroas closed 4 months ago

isidroas commented 4 months ago
$ python -m pytest  tests/test_album.py tests/test_api.py tests/test_artist.py  tests/test_base.py tests/test_genius.py tests/test_public_methods.py tests/test_song.py tests/test_utils.py  
=============================================================================================== test session starts ================================================================================================
platform linux -- Python 3.10.12, pytest-8.0.1, pluggy-1.4.0
rootdir: /tmp/LyricsGenius
collected 97 items

tests/test_album.py ......                                                                                                                                                                                   [  6%]
tests/test_api.py F.F....                                                                                                                                                                                    [ 13%]
tests/test_artist.py ..........                                                                                                                                                                              [ 23%]
tests/test_base.py .                                                                                                                                                                                         [ 24%]
tests/test_genius.py ....FF                                                                                                                                                                                  [ 30%]
tests/test_public_methods.py ........................................................                                                                                                                        [ 88%]
tests/test_song.py ..F.....                                                                                                                                                                                  [ 96%]
tests/test_utils.py F..                                                                                                                                                                                      [100%]

============================================================================================= short test summary info ==============================================================================================
FAILED tests/test_api.py::TestAPI::test_account - requests.exceptions.HTTPError: [Errno 401] 401 Client Error: Unauthorized for url: https://api.genius.com/account?text_format=plain
FAILED tests/test_api.py::TestAPI::test_manage_annotation - requests.exceptions.HTTPError: [Errno 403] 403 Client Error: Forbidden for url: https://api.genius.com/annotations?text_format=plain
FAILED tests/test_genius.py::TestLyrics::test_lyrics_with_id - AssertionError: False is not true
FAILED tests/test_genius.py::TestLyrics::test_lyrics_with_url - AssertionError: False is not true
FAILED tests/test_song.py::TestSong::test_lyrics_raw - AssertionError: False is not true
FAILED tests/test_utils.py::TestUtils::test_auth_from_environment - AssertionError: False is not true
===================================================================================== 6 failed, 91 passed in 161.43s (0:02:41) =====================================================================================

For test_auth.py I got this:

export GENIUS_CLIENT_ID=....
export GENIUS_CLIENT_SECRET=...
$ python -m pytest tests/test_auth.py                    git:(master|)
========================================== test session starts ===========================================
platform linux -- Python 3.10.12, pytest-8.0.1, pluggy-1.4.0
rootdir: /tmp/LyricsGenius
collected 0 items / 1 error

================================================= ERRORS =================================================
__________________________________ ERROR collecting tests/test_auth.py ___________________________________
tests/test_auth.py:11: in <module>
    redirect_uri = os.environ["GENIUS_REDIRECT_URI"]
/usr/lib/python3.10/os.py:680: in __getitem__
    raise KeyError(key) from None
E   KeyError: 'GENIUS_REDIRECT_URI'
======================================== short test summary info =========================================
ERROR tests/test_auth.py - KeyError: 'GENIUS_REDIRECT_URI'
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Interrupted: 1 error during collection !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
============================================ 1 error in 0.20s ============================================

What is the correct value for GENIUS_REDIRECT_URI?

2024-02-20-191101_blur

I also noted that the Github CI is failing, but the reports are gone: https://github.com/johnwmillr/LyricsGenius/actions/runs/6388061122/job/17337302061

allerter commented 4 months ago

You need to set the env var GENIUS_REDIRECT_URI to be able to run tests. I believe any valid URL would suffice. For example https://example.com/callback.

isidroas commented 4 months ago

It worked, thank you

export GENIUS_REDIRECT_URI=https://example.com/callback
$ python -m pytest tests/test_auth.py
================================ test session starts ================================
platform linux -- Python 3.10.12, pytest-8.0.1, pluggy-1.4.0
rootdir: /tmp/LyricsGenius
collected 6 items

tests/test_auth.py ......                                                     [100%]

================================= 6 passed in 0.52s =================================
isidroas commented 4 months ago

Closing

Maybe, another issue could be created to: