cle-b / httpdbg

A tool for Python developers to easily debug the HTTP(S) client requests in a Python program.
https://httpdbg.readthedocs.io/
Apache License 2.0
550 stars 13 forks source link

Question: Setting initiators in source #147

Open machadocs opened 1 day ago

machadocs commented 1 day ago

Hello,

Is there a way to explicitly set an initiator name in source?


For context, I am using httpdbg in pytest and would like to have separate initiator groups for fixtures and items (tests) that make requests. Currently, it seems that all requests made in setup/call/teardown phases are grouped under a single initiator for the item.

Example

@pytest.fixture(scope='session')
def loaded_stuff():
    return requests.get("/some/url").json()

def test_a(loaded_stuff):
    response = requests.post("/some/second/url", json=loaded_stuff)
    assert response.ok

def test_b(loaded_stuff):
    response = requests.post("/some/third/url", json=loaded_stuff)
    assert response.ok

The httpdbg output for the code above would show requests like so:

Note that requests made in the loaded_stuff fixture are grouped under the test_a initiator, while the test_b initiator omits requests made in loaded_stuff due to its scope.

Ideally I would have the requests made in loaded_stuff under its own initiator - so is there a way I can set the initiator explicitly when inside a fixture?

cle-b commented 16 hours ago

Hello :)

No, it is not possible to add anything to your code to change the initiator when using pytest.

I am working on a solution to include information about the pytest fixture in the UI.