0

I am trying to use snapshottest for some pytests in Python.

The stored snapshot of correct behavior is (and where I suspect the problem lays)

snapshots['test_some_unauthorized 1'] = GenericRepr('<Response [401]>')

def test_some_unauthorized(snapshot):
    ...
    snapshot.assert_match(response)
  • this test only reacts on the status code. No matter what content is returned.

However error code does not imply clean data nor any valid error content anyways.

Is there something I am missing? Maybe some "check error response contents"-settings or something?

(BTW: I know I can bypass this with checking the response content directly explicitly somewhat like
assert response.text == "...", however I wanted to use snapshottest to avoid doing exactly that, so my question aim is really how to do this using snapshot)

jave.web
  • 13,880
  • 12
  • 91
  • 125
  • 1
    `` is probably the `__repr__` version of the response object, so you're effectively only testing whether the repr version of the object is the same; not that the objects actually have the same content. An option is possibly to snapshot `(status_code, body)` or something similar instead where the representation contains everything you want to validate. `snapshottest` seems to be concerned with the string representation, not an frozen/hydrated version of the object (which would contain many request-specific things, such as `Date`-headers, etc.) – MatsLindh Jul 07 '21 at 21:18
  • @MatsLindh oooh, so I should've been testing more like `assert response.status_code == 401` and `snapshot.assert_match(response.text)`, thanks – jave.web Jul 08 '21 at 09:56
  • Yes, that sounds far more reasonable. – MatsLindh Jul 08 '21 at 10:07

0 Answers0