Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Plugin does not loaded #9

Closed
vitalk opened this issue Oct 27, 2014 · 14 comments
Closed

Plugin does not loaded #9

vitalk opened this issue Oct 27, 2014 · 14 comments

Comments

@vitalk
Copy link
Collaborator

vitalk commented Oct 27, 2014

Re #7 (comment)

Looks like a pytest-flask not loaded at all:

available fixtures: pytestconfig, app, recwarn, monkeypatch, capfd, capsys, tmpdir

Can you provide a head of your pytest stack trace? The list of loaded
plugins shows at the top, for example:

$ py.test tests/
test session starts
platform darwin -- Python 2.7.8 -- py-1.4.24 -- pytest-2.6.2
plugins: flask
collected 443 items

...

/cc @bonya

@bonya
Copy link

bonya commented Oct 27, 2014

platform linux2 -- Python 2.7.3 -- py-1.4.26 -- pytest-2.6.4 -- /usr/bin/python
plugins: xdist
collected 2 items / 2 errors
pip list | grep pytest
pytest (2.6.4)
pytest-flask (0.3.4)
pytest-xdist (1.9)

@vitalk
Copy link
Collaborator Author

vitalk commented Oct 27, 2014

pytest-flask and pytest-xdist installed on the same way?

@bonya
Copy link

bonya commented Oct 27, 2014

yes. all packages are installed via pip.

@vitalk
Copy link
Collaborator Author

vitalk commented Oct 27, 2014

I can't reproduce your environment, can you run a simplest example (something like in #7 (comment))?

@vitalk
Copy link
Collaborator Author

vitalk commented Oct 27, 2014

platform darwin -- Python 2.7.8 -- py-1.4.26 -- pytest-2.6.4
plugins: flask, xdist
collected 1 items

test_app.py .

=== 1 passed in 0.02 seconds ===
vital@macbook .../tmp-1fdb6130449b8aa2 workon tmp-1fdb6130449b8aa2
$ pip list | grep pytest
pytest (2.6.4)
pytest-flask (0.3.4)
pytest-xdist (1.11)

@bonya
Copy link

bonya commented Oct 27, 2014

I did following

import pytest

def create_app():
    from flask import Flask, jsonify
    app = Flask(__name__)

    @app.route('/ping')
    def ping():
        return jsonify(ping='pong')

    return app


@pytest.fixture
def app():
    app = create_app()
    app.debug = True
    return app


class TestApp:

    def test_ping(self, client):
        res = client.get(url_for('ping'))
        assert res.status_code == 200
        assert res.json == {'ping': 'pong'}


if __name__ == '__main__':
    app = create_app()
    app.run(port=5000)

the output

vagrant@talkstart:/vagrant$ py.test tests/test_xxx.py
====================================================================== test session starts ======================================================================
platform linux2 -- Python 2.7.3 -- py-1.4.26 -- pytest-2.6.4
plugins: xdist
collected 1 items

tests/test_xxx.py E

============================================================================ ERRORS =============================================================================
______________________________________________________________ ERROR at setup of TestApp.test_ping ______________________________________________________________
file /vagrant/tests/test_xxx.py, line 25
      def test_ping(self, client):
        fixture 'client' not found
        available fixtures: pytestconfig, app, recwarn, monkeypatch, capfd, capsys, tmpdir
        use 'py.test --fixtures [testpath]' for help on them.

pytest plugin is not loaded.

@bonya
Copy link

bonya commented Oct 27, 2014

So, i upgraded my vagrant box to ubuntu 14.04 and python 2.7.6 and it works.

Probably older python 2.7.3 was causing the issue.

Thanks for the fast replies!

@vitalk
Copy link
Collaborator Author

vitalk commented Oct 27, 2014

👍 happy testing.

@vitalk vitalk closed this as completed Oct 27, 2014
@evadeflow
Copy link

Here's a possibly relevant anecdote: I was getting exactly the fixture 'client' not found error described in this issue, even though pytest-flask was already installed. On a random hunch, I ran pip install ipython and—after doing that—the pytest-flask plugin loaded fine. Not that I'm suggesting that installing ipython is a proper 'fix' for this. But perhaps it provides a clue as to the root cause.

@vitalk
Copy link
Collaborator Author

vitalk commented Mar 11, 2016

Thanks @evadeflow for a note. But this looks a little bit strange for me. Do you update your python/pytest environment at first, as mentioned before?

@kabapy
Copy link

kabapy commented Nov 9, 2017

add the required fixture

@pytest.fixture
def client():
    app = create_app()
    client = app.test_client()
    return client

@senaps
Copy link

senaps commented Dec 12, 2017

@kabapy if i do so, then i'll get an error telling me url_for needs to be ran with a context-manager.

i have the same issue of not being able to find client fixture.

@senaps
Copy link

senaps commented Dec 13, 2017

i was able to pass the test's by removing pytest, pytest-flask and installing them again.

https://stackoverflow.com/a/47786621/937453

@kabapy
Copy link

kabapy commented Dec 13, 2017

I avoid flask-pytest and use pytest directly

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants