singingwolfboy / flask-dance

Doing the OAuth dance with style using Flask, requests, and oauthlib.
https://pypi.python.org/pypi/Flask-Dance/
MIT License
1.01k stars 158 forks source link

Failing tests/fixtures/test_pytest.py in the Debian build #401

Closed utkarsh2102 closed 1 year ago

utkarsh2102 commented 2 years ago

Hello,

Thank you very much for your work on this! However, whilst trying to package this module for Debian, I seem to run into this test failure around fixtures:

I: pybuild base:239: python3-coverage run -m pytest
============================= test session starts ==============================
platform linux -- Python 3.10.6, pytest-7.1.2, pluggy-1.0.0+repack
rootdir: /<<PKGBUILDDIR>>
plugins: mock-3.8.2, betamax-0.8.1
collected 192 items

tests/test_utils.py ..                                                   [  1%]
tests/consumer/test_oauth1.py ....................                       [ 11%]
tests/consumer/test_oauth2.py ........................                   [ 23%]
tests/consumer/test_requests.py ..........                               [ 29%]
tests/consumer/storage/test_sqla.py ............                         [ 35%]
tests/contrib/test_atlassian.py ......                                   [ 38%]
tests/contrib/test_authentiq.py ....                                     [ 40%]
tests/contrib/test_azure.py .......                                      [ 44%]
tests/contrib/test_digitalocean.py .....                                 [ 46%]
tests/contrib/test_discord.py ....                                       [ 48%]
tests/contrib/test_dropbox.py ........                                   [ 53%]
tests/contrib/test_facebook.py .....                                     [ 55%]
tests/contrib/test_fitbit.py ...                                         [ 57%]
tests/contrib/test_github.py ...                                         [ 58%]
tests/contrib/test_gitlab.py ......                                      [ 61%]
tests/contrib/test_google.py .............                               [ 68%]
tests/contrib/test_heroku.py ...                                         [ 70%]
tests/contrib/test_jira.py .......                                       [ 73%]
tests/contrib/test_linkedin.py ...                                       [ 75%]
tests/contrib/test_meetup.py ....                                        [ 77%]
tests/contrib/test_nylas.py ...                                          [ 79%]
tests/contrib/test_osm.py ...                                            [ 80%]
tests/contrib/test_reddit.py ....                                        [ 82%]
tests/contrib/test_salesforce.py ........                                [ 86%]
tests/contrib/test_slack.py .........                                    [ 91%]
tests/contrib/test_spotify.py ...                                        [ 93%]
tests/contrib/test_strava.py ...                                         [ 94%]
tests/contrib/test_twitch.py ...                                         [ 96%]
tests/contrib/test_twitter.py ...                                        [ 97%]
tests/contrib/test_zoho.py ...                                           [ 99%]
tests/fixtures/test_pytest.py E                                          [100%]

==================================== ERRORS ====================================
_______________________ ERROR at setup of test_home_page _______________________
file /<<PKGBUILDDIR>>/tests/fixtures/test_pytest.py, line 44
  @pytest.mark.usefixtures("betamax_record_flask_dance")
  def test_home_page(app):
E       fixture 'betamax_record_flask_dance' not found
>       available fixtures: app, betamax_parametrized_recorder, betamax_parametrized_session, betamax_recorder, betamax_session, cache, capfd, capfdbinary, caplog, capsys, capsysbinary, class_mocker, doctest_namespace, flask_dance_sessions, mocker, module_mocker, monkeypatch, package_mocker, pytestconfig, record_property, record_testsuite_property, record_xml_attribute, recwarn, responses, session_mocker, tmp_path, tmp_path_factory, tmpdir, tmpdir_factory
>       use 'pytest --fixtures [testpath]' for help on them.

D'you have any idea how to get this working? TIA! \o/

utkarsh2102 commented 2 years ago

OTOH, if I run the tests like: python3-coverage run -m pytest --fixtures ./flask_dance/fixtures/pytest.py

All the tests are skipped. 😭

utkarsh2102 commented 2 years ago

Logs for above are:

I: pybuild base:239: python3-coverage run -m pytest --fixtures ./flask_dance/fixtures/pytest.py
============================= test session starts ==============================
platform linux -- Python 3.10.6, pytest-7.1.2, pluggy-1.0.0+repack
rootdir: /<<PKGBUILDDIR>>
plugins: mock-3.8.2, betamax-0.8.1
collected 0 items
cache -- .../_pytest/cacheprovider.py:510
    Return a cache object that can persist state between testing sessions.

capsys -- .../_pytest/capture.py:878
    Enable text capturing of writes to ``sys.stdout`` and ``sys.stderr``.

capsysbinary -- .../_pytest/capture.py:895
    Enable bytes capturing of writes to ``sys.stdout`` and ``sys.stderr``.

capfd -- .../_pytest/capture.py:912
    Enable text capturing of writes to file descriptors ``1`` and ``2``.

capfdbinary -- .../_pytest/capture.py:929
    Enable bytes capturing of writes to file descriptors ``1`` and ``2``.

doctest_namespace [session scope] -- .../_pytest/doctest.py:731
    Fixture that returns a :py:class:`dict` that will be injected into the
    namespace of doctests.

pytestconfig [session scope] -- .../_pytest/fixtures.py:1334
    Session-scoped fixture that returns the session's :class:`pytest.Config`
    object.

record_property -- .../_pytest/junitxml.py:282
    Add extra properties to the calling test.

record_xml_attribute -- .../_pytest/junitxml.py:305
    Add extra xml attributes to the tag for the calling test.

record_testsuite_property [session scope] -- .../_pytest/junitxml.py:343
    Record a new ``<property>`` tag as child of the root ``<testsuite>``.

tmpdir_factory [session scope] -- .../_pytest/legacypath.py:295
    Return a :class:`pytest.TempdirFactory` instance for the test session.

tmpdir -- .../_pytest/legacypath.py:302
    Return a temporary directory path object which is unique to each test
    function invocation, created as a sub directory of the base temporary
    directory.

caplog -- .../_pytest/logging.py:487
    Access and control log capturing.

monkeypatch -- .../_pytest/monkeypatch.py:29
    A convenient fixture for monkey-patching.

recwarn -- .../_pytest/recwarn.py:29
    Return a :class:`WarningsRecorder` instance that records all warnings emitted by test functions.

tmp_path_factory [session scope] -- .../_pytest/tmpdir.py:184
    Return a :class:`pytest.TempPathFactory` instance for the test session.

tmp_path -- .../_pytest/tmpdir.py:199
    Return a temporary directory path object which is unique to each test
    function invocation, created as a sub directory of the base temporary
    directory.

---------------- fixtures defined from betamax.fixtures.pytest -----------------
betamax_parametrized_recorder -- ../../../usr/lib/python3/dist-packages/betamax/fixtures/pytest.py:110
    Generate a recorder with a session that has Betamax already installed.

betamax_parametrized_session -- ../../../usr/lib/python3/dist-packages/betamax/fixtures/pytest.py:137
    Generate a session that has Betamax already installed.

betamax_recorder -- ../../../usr/lib/python3/dist-packages/betamax/fixtures/pytest.py:72
    Generate a recorder with a session that has Betamax already installed.

betamax_session -- ../../../usr/lib/python3/dist-packages/betamax/fixtures/pytest.py:95
    Generate a session that has Betamax already installed.

------------------- fixtures defined from pytest_mock.plugin -------------------
class_mocker [class scope] -- ../../../usr/lib/python3/dist-packages/pytest_mock/plugin.py:407
    Return an object that has the same interface to the `mock` module, but
    takes care of automatically undoing all patches after each test method.

mocker -- ../../../usr/lib/python3/dist-packages/pytest_mock/plugin.py:407
    Return an object that has the same interface to the `mock` module, but
    takes care of automatically undoing all patches after each test method.

module_mocker [module scope] -- ../../../usr/lib/python3/dist-packages/pytest_mock/plugin.py:407
    Return an object that has the same interface to the `mock` module, but
    takes care of automatically undoing all patches after each test method.

package_mocker [package scope] -- ../../../usr/lib/python3/dist-packages/pytest_mock/plugin.py:407
    Return an object that has the same interface to the `mock` module, but
    takes care of automatically undoing all patches after each test method.

session_mocker [session scope] -- ../../../usr/lib/python3/dist-packages/pytest_mock/plugin.py:407
    Return an object that has the same interface to the `mock` module, but
    takes care of automatically undoing all patches after each test method.

-------------- fixtures defined from flask_dance.fixtures.pytest ---------------
betamax_record_flask_dance -- flask_dance/fixtures/pytest.py:55
    Wraps the specified Flask-Dance sessions with Betamax

============================ no tests ran in 0.23s =============================
singingwolfboy commented 2 years ago

Maybe problem is that flask_dance isn't properly installed when you run the tests? This fixture is installed using the entry_points system documented here: https://docs.pytest.org/en/7.1.x/how-to/writing_plugins.html#setuptools-entry-points

You can see the entry point definition in setup.py and the code itself in flask_dance/fixtures/pytest.py. Does that help you debug the issue?

utkarsh2102 commented 2 years ago

Hellu! Thank you very much but these are build-time tests. So these are running whilst building the package and not running in the installed form. :/

singingwolfboy commented 2 years ago

The command you posted (python3-coverage run -m pytest) has nothing to do with building a Python package. It may be part of how Debian builds packages, but that's a different system.

In order to make this test pass, you will need to install the Python package first, which is typically done using pip. In this case, you can make it an "editable" install, so that pip links the files from their existing location rather than copying them to the site-packages directory. Once you install flask_dance with pip, the pytest fixtures should be registered and available for tests to use. Does that make sense? I don't know how familiar you are with the Python packaging ecosystem.

utkarsh2102 commented 2 years ago

Hello,

The command you posted (python3-coverage run -m pytest) has nothing to do with building a Python package. It may be part of how Debian builds packages, but that's a different system.

Aah, yes. I should've mentioned that. Debian's build system also includes tests during build time.

In order to make this test pass, you will need to install the Python package first, which is typically done using pip. In this case, you can make it an "editable" install, so that pip links the files from their existing location rather than copying them to the site-packages directory. Once you install flask_dance with pip, the pytest fixtures should be registered and available for tests to use. Does that make sense? I don't know how familiar you are with the Python packaging ecosystem.

I do understand that and it makes sense. However, on the Debian side, we have two sorts of testing - during the build time and then in the installed form. The fixture tests don't work during the build time (because those fixtures are not registered and thus not available) but they work just fine when tests are run in the installed form.

So let me paraphrase my question: since they're working fine in the installed form of the package, is there a way to make them work during the build time as well? When the package is not installed. Alternatively, are these fixture tests NOT meant to run during the build time? D'you know if there's a neat way of not running them during build time (that is, some sorta flags passed to pytest or something)?

utkarsh2102 commented 2 years ago

Hi @singingwolfboy,

So let me paraphrase my question: since they're working fine in the installed form of the package, is there a way to make them work during the build time as well? When the package is not installed. Alternatively, are these fixture tests NOT meant to run during the build time? D'you know if there's a neat way of not running them during build time (that is, some sorta flags passed to pytest or something)?

Slight ping on this one^, please. No rush, I just wanted to ensure this didn't fall through the cracks. I am just trying to get this test sorted for the build-time tests. Let me know if you have any suggestions, opinions, or questions. TIA!

singingwolfboy commented 2 years ago

Oops, thanks for the reminder! I just pushed a new version that allows you to run the tests without the ones that require the package to be installed. To do so, run:

pytest -m "not install_required"
# or, if you want to also generate coverage:
coverage run -m pytest -m "not install_required"

The test suite uses pytest marks to accomplish this. Let me know if that works for you, or if you need anything else to make this work!