Giter VIP home page Giter VIP logo

Comments (2)

csernazs avatar csernazs commented on August 29, 2024

Hi there,

Sorry for the late answer.

You can create as many http servers as you want for your test.
I would recommend using the https as you wrote in the issue, and then creating a http one by copying the logic from the make_httpserver function here and making your own fixture.

So you would have two fixtures at the end, one for http, other for https.

You would need to create handlers for both, probably a redirect for the http.

from pytest-httpserver.

Spitfire1900 avatar Spitfire1900 commented on August 29, 2024

Thanks for getting back, I had answered this myself awhile ago but never posted an update.

In my case I did the following to create a parameterized version of a test that evaluated HTTP and HTTPS permutation.

@pytest.fixture(scope="session")
def cert_authority() -> trustme.CA:
    return trustme.CA()


@pytest.fixture(scope="session", params=['http', 'https'])
def make_httpserver(cert_authority: trustme.CA, request: pytest.FixtureRequest):  # pylint: disable=redefined-outer-name
    ssl_context = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER) if request.param == 'https' else None
    if ssl_context:
        localhost_cert = cert_authority.issue_cert("localhost")
        localhost_cert.configure_cert(ssl_context)
    http_server = HTTPServer(ssl_context=ssl_context)
    http_server.start()
    yield http_server
    http_server.clear()
    if http_server.is_running():
        http_server.stop()


def test_url(resource_path_root: Path, httpserver: HTTPServer, cert_authority: trustme.CA):  # pylint: disable=redefined-outer-name
    <test_impl....>

from pytest-httpserver.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.