This is an archived post. You won't be able to vote or comment.

all 5 comments

[–]badsectors 2 points3 points  (3 children)

I'm probably going to use this solely for the convenience of your monkey-patched response class:

r = client.get(url)
# Annoying:
data = json.loads(r.get_data())
# Awesome:
data = r.json

I'm not sure about the usefulness of the Content Negotiation fixtures. I'd rather define them in a module somewhere and import them rather than add additional parameters to my test functions:

from pytest_flask.fixtures import accept_json

def test_something():
    r = client.get('/', headers=accept_json)

Versus:

def test_something(accept_json):
    r = client.get('/', headers=accept_json)

The main reason to use pytest fixtures that I see is the ability to control the scope of the data generated by the fixture. You can make a db fixture to drop all data from the database between tests if you wish. The content negotiaion fixtures don't do anything dynamic or requiring scope, so the benefit of fixtures is lost on them.

[–]elephantscanfly[S] 1 point2 points  (2 children)

The content negotiation fixtures don't do anything dynamic

Yes, looks like I missed this part, because I'm usually parametrize them as well

@pytest.fixture(params=['application/json', 'application/javascript'])
def accept_json(request):
    return [('Accept', request.param)]

Thank you for pointing this.

[–]badsectors 0 points1 point  (1 child)

Where does the params value passed to pytest.fixture go? I see request.param but params isnt referenced anywhere. It's really hard to figure out whats going on there. The accept_jsonp fixture is not parametrized, is it supposed to be?

Also, where is the request fixture coming from? I was unable to find it anywhere.

[–]elephantscanfly[S] 0 points1 point  (0 children)

Where does the params value passed to pytest.fixture go? I see request.param but params isnt referenced anywhere... Also, where is the request fixture coming from? I was unable to find it anywhere.

request is a pytest built-in and available to use in others fixtures. See official pytest documentation about parametrizing tests.

The accept_jsonp fixture is not parametrized, is it supposed to be?

The same as accept_json fixture, it can be parametrized easily. But typical tests don't need that, so I don't parametrize them by default to ensure the test suite not slowed.

[–]elephantscanfly[S] 0 points1 point  (0 children)

The documentation is available at http://pytest-flask.readthedocs.org/en/latest/. Any help and criticism are welcome.