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

cleanup_unserializable results in weird handling of unserializable user_properties

Open The-Compiler opened this issue 4 years ago • 4 comments

This file:

def test_user_properties_list(record_property):
    record_property("hello", ["world", "mars"])

def test_user_properties_set(record_property):
    record_property("hello", {"world", "mars"})

results in the following reports (pretty printed for readability):

{
  "nodeid": "test_replog.py::test_user_properties_list",
  "location": [
    "test_replog.py",
    0,
    "test_user_properties_list"
  ],
  "keywords": {
    "test_replog.py": 1,
    "test_user_properties_list": 1,
    "autpy": 1
  },
  "outcome": "passed",
  "longrepr": null,
  "when": "call",
  "user_properties": [
    [
      "hello",
      [
        "world",
        "mars"
      ]
    ]
  ],
  "sections": [],
  "duration": 8.534699736628681e-05,
  "$report_type": "TestReport"
}
{
  "nodeid": "test_replog.py::test_user_properties_set",
  "location": [
    "test_replog.py",
    3,
    "test_user_properties_set"
  ],
  "keywords": {
    "test_replog.py": 1,
    "test_user_properties_set": 1,
    "autpy": 1
  },
  "outcome": "passed",
  "longrepr": null,
  "when": "call",
  "user_properties": "[('hello', {'mars', 'world'})]",
  "sections": [],
  "duration": 0.00017495399515610188,
  "$report_type": "TestReport"
}

Note the different storage of user_properties:

  "user_properties": [
    [
      "hello",
      [
        "world",
        "mars"
      ]
    ]
  ],
  "user_properties": "[('hello', {'mars', 'world'})]",

i.e. if an user property value is unserializable, the entire value gets turned into a string, rather than turning that specific property into one.

The-Compiler avatar Oct 04 '21 15:10 The-Compiler

@nicoddemus i propose we switch to a own json encoder that replaces single broken objects with

{"$unserializable": str(x)}

RonnyPfannschmidt avatar May 02 '23 09:05 RonnyPfannschmidt

@The-Compiler

the entire value gets turned into a string, rather than turning that specific property into one.

To be clear, would you expect this?

  "user_properties": [
    [
      "hello", 
      "{'mars', 'world'}"
    ]
  ],

@RonnyPfannschmidt do you mean something like this?

  "user_properties": [
    [
      "hello", 
      {"$unserializable": "{'mars', 'world'}"}      
    ]
  ],

nicoddemus avatar May 03 '23 11:05 nicoddemus

@nicoddemus see the draft mr

RonnyPfannschmidt avatar May 03 '23 11:05 RonnyPfannschmidt

Ahh I see, so #35 will output:

  "user_properties": [
    [
      "hello", 
      {"$no-json": "{'mars', 'world'}"}      
    ]
  ],

What do you think @The-Compiler ?

nicoddemus avatar May 03 '23 11:05 nicoddemus