pytest-reportlog icon indicating copy to clipboard operation
pytest-reportlog copied to clipboard

use pinpointed handling of non-serializable data

Open RonnyPfannschmidt opened this issue 2 years ago • 10 comments

fixes #12

the caveat is that now we sometimes have magic json objects in the depth of a message to fix the details

this also exposed a bug in warning record message handling that was hidden by the broad str magic

RonnyPfannschmidt avatar May 02 '23 10:05 RonnyPfannschmidt

@RonnyPfannschmidt can you please rebase on main? Thanks!

nicoddemus avatar May 03 '23 11:05 nicoddemus

@nicoddemus done

RonnyPfannschmidt avatar May 03 '23 12:05 RonnyPfannschmidt

LGTM, let's see what @The-Compiler has to say.

nicoddemus avatar May 03 '23 12:05 nicoddemus

Sorry for the delay, just came back from Berlin for yet another pytest company training on Saturday :sweat_smile:

Just dug into the git history of the project where this happened to me, and I basically accidentally serialized a set instead of a list. I suppose this behavior makes sense. I wonder if a TypeError might make even more sense, but I suppose it would be a bit in the way if people use record_property for other stuff?

Either way, this seems fine to me. Perhaps "handle unserializable objects with a pinpointed marker" in the changelog should be a bit more specific so people know what to watch out for?

The-Compiler avatar May 08 '23 12:05 The-Compiler

Perhaps a little bikeshedding can help

It might also be a good idea to switch from str to safe_repr

RonnyPfannschmidt avatar May 08 '23 12:05 RonnyPfannschmidt

Some questions to ponder on:

  • Why are we doing this instead of raising a TypeError?

Probably so someone with previous usage of record_property can start using the plugin without things exploding?

  • Do we foresee people using the actual values, or is this basically just included as debugging output?

I'd say debugging output?

  • If the latter, would it suffice if we just included the keys instead, and leave the values out entirely? After all, they might be rather noisy, if e.g. containing Python memory addresses which change every time.

IMHO it would be fine? But I can see there is value in seeing the value (hah) too.

The-Compiler avatar May 08 '23 13:05 The-Compiler

If we switch from str to length limited safe repr, I think we will be fine

RonnyPfannschmidt avatar May 08 '23 13:05 RonnyPfannschmidt

Probably so someone with previous usage of record_property can start using the plugin without things exploding?

It was introduced here:

https://github.com/pytest-dev/pytest-reportlog/commit/bac07c31f0d70d31facf8ce3fa5ac913c4a411d3

~~I don't recall the details, but probably xdist was including JSON-incompatible data into the reports.~~ Problem is described here: #5

nicoddemus avatar May 10 '23 13:05 nicoddemus

@nicoddemus xdist adds report.node but doesnt expand report serialization to turn it into json compatible objects atm

RonnyPfannschmidt avatar May 10 '23 13:05 RonnyPfannschmidt

Yes (you probably did not see my edit where I found the reason after the initial post hehehe)

nicoddemus avatar May 10 '23 14:05 nicoddemus