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.

Issues on using schemathesis with pytest-aiohttp

See original GitHub issue

Hi,

First, thanks for a great library and an effort behind!

I’m happy to try it, but ran into the issue, after tried to integrate it with my aiohttp.web application via next test case:

from pathlib import Path

import schemathesis
from petstore.app import create_app


schema = schemathesis.from_path(
    Path(__file__).parent / "petstore-expanded.yaml"
)


@schema.parametrize()
async def test_petstore(aiohttp_client, case):
    client = await aiohttp_client(create_app())
    response = await client.request(
        case.method, case.formatted_path, headers=case.headers, json=case.json
    )
    assert response.status < 500

Where,

  • aiohttp_client is a fixture from pytest-aiohttp
  • petstore.app:create_app factory for creating web.Application

This test case results in,

E       fixture 'case' not found
>       available fixtures: aiohttp_client, aiohttp_raw_server, aiohttp_server, aiohttp_unused_port, cache, capfd, capfdbinary, caplog, capsys, capsysbinary, cov, doctest_namespace, fast, loop, loop_debug, monkeypatch, no_cover, proactor_loop, pytestconfig, raw_test_server, record_property, record_testsuite_property, record_xml_attribute, recwarn, subtests, test_client, test_server, tmp_path, tmp_path_factory, tmpdir, tmpdir_factory, unused_port
>       use 'pytest --fixtures [testpath]' for help on them.

after running pytest as,

python -m pytest /path/to/file/with_test.py

More data that might be helpful,

  • Python 3.7.4
  • OS: macOS 10.14.4
  • pytest: 5.2.1
  • hypothesis profile ‘default’ -> database=DirectoryBasedExampleDatabase(‘/Users/playpauseandstop/Projects/rororo/.hypothesis/examples’)
  • pytest plugins: schemathesis-0.8.1, subtests-0.2.1, aiohttp-0.3.0, hypothesis-4.39.0, cov-2.8.1

Maybe, I got the concept behind schemathesis wrong, but I thought that I’m being able to,

  • Make the schema instance from the OpenAPI 3.0 schema file, which stores next to test case module
  • Wrap my test case with @schema.parametrize() decorator
  • Create my web.Application and test aiohttp_client inside the test
  • Run the test
  • And ensure that schema from the file covered well by my aiohttp.web application

If this not possible, I will happy to know on proposed workflow to test my aiohttp.web application with schemathesis.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
Stranger6667commented, Oct 8, 2019

Hej @playpauseandstop ! The problem should be solved in the master branch. We will issue a new release tomorrow 😃 I’ll update when it will be done

0reactions
playpauseandstopcommented, Oct 8, 2019

Thanks a lot @Stranger6667!

I haven’t time today to play with your proposed solution from https://github.com/kiwicom/schemathesis/issues/121#issuecomment-539109526, so looking forward to try new release instead.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Issues on using schemathesis with pytest-aiohttp #121 - GitHub
1. Maybe, I got the concept behind schemathesis wrong, but I thought that I'm being able to,. Make the schema instance from the...
Read more >
Frequently Asked Questions - Schemathesis - Read the Docs
Schemathesis uses Property-Based Testing to infer all input values and uses examples defined in the API schema as separate test cases.
Read more >
schemathesis/schemathesis - Gitter
Hi all. I hit some strange issue, schemathesis generating invalid JSON payload, and producing SyntaxError. For example: Schema (relevant part of actual docs)....
Read more >
https://raw.githubusercontent.com/regro/cf-graph-c...
... regro-bot pypi_name: flake8-use-pathlib flake8-variables-names: conda_name: ... mapping_source: regro-bot pypi_name: pytest-aiohttp pytest-alembic: ...
Read more >
Using Hypothesis and Schemathesis to Test FastAPI
This article looks at how property-based testing via Hypothesis and Schemathesis can be used to test FastAPI.
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