question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[proposition] pytest fixture

See original GitHub issue

Have you thought about making a fixture for pytest?

it would be extremely great to be able to use webtest like this

@pytest.mark.django_db
def test_django(app):
    resp = app.get('/smth/', user='smone')
    form = resp.forms['main']
    form['some_field'] = 'smth'
    submitted = form.submit()
    assert submitted.status_int == 200

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:18 (15 by maintainers)

github_iconTop GitHub Comments

1reaction
gawelcommented, Feb 24, 2017

https://github.com/django-webtest/django-webtest/pull/62

You can specify options in a (setup|pytest).cfg and override it from the command line when needed

1reaction
merwokcommented, Feb 24, 2017

No globals!


import pytest


@pytest.fixture(scope='session')
def app_mixin():
    # See https://github.com/django-webtest/django-webtest/issues/64
    from django_webtest import WebTestMixin
    app_mixin = WebTestMixin()
    # These envvars make webtest app responses look like django client responses
    app_mixin.extra_environ = {'HTTP_HOST': 'testserver'}
    return app_mixin



@pytest.yield_fixture
def app(app_mixin):
    app_mixin._patch_settings()
    app_mixin.renew_app()
    yield app_mixin.app

    app_mixin._unpatch_settings()
Read more comments on GitHub >

github_iconTop Results From Across the Web

pytest fixtures: explicit, modular, scalable
“Fixtures”, in the literal sense, are each of the arrange steps and data. They're everything that test needs to do its thing. At...
Read more >
Create A Yield Pytest Fixture - Cameron Maske
Short, instructive video on using a pytest yield fixture to add teardown logic to keep your test isolated. The example show to extend...
Read more >
Pytest Tutorial: Sharing Fixtures Through conftest - YouTube
Pytest Tutorial: Sharing Fixtures Through conftestPytest fixtures are one of the core features that make pytest framework stand out above ...
Read more >
How to synchronize parametrization across pytest fixtures?
Your last proposition is the best one. – MrBean Bremen. Aug 7, 2020 at 6:01. Add a ...
Read more >
Fixture "..." called directly · Issue #3950 · pytest-dev ... - GitHub
_pytest/fixtures.py:799: RemovedInPytest4Warning: Fixture "..." called directly. Fixtures are not meant to be called directly, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found