Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cleanup_unserializable results in weird handling of unserializable user_properties #12

Open
The-Compiler opened this issue Oct 4, 2021 · 4 comments · May be fixed by #35
Open

cleanup_unserializable results in weird handling of unserializable user_properties #12

The-Compiler opened this issue Oct 4, 2021 · 4 comments · May be fixed by #35
Labels
bug Something isn't working

Comments

@The-Compiler
Copy link
Member

The-Compiler commented Oct 4, 2021

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.

@RonnyPfannschmidt RonnyPfannschmidt added the bug Something isn't working label Oct 4, 2021
@RonnyPfannschmidt
Copy link
Member

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

{"$unserializable": str(x)}

RonnyPfannschmidt added a commit to RonnyPfannschmidt/pytest-reportlog that referenced this issue May 2, 2023
instead of str

this creates a difference in logged data
warning messages needed a change
instead of toplevel values, only the sub-object is affected
@nicoddemus
Copy link
Member

@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'}"}      
    ]
  ],

@RonnyPfannschmidt
Copy link
Member

@nicoddemus see the draft mr

@nicoddemus
Copy link
Member

Ahh I see, so #35 will output:

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

What do you think @The-Compiler ?

RonnyPfannschmidt added a commit to RonnyPfannschmidt/pytest-reportlog that referenced this issue May 3, 2023
instead of str

this creates a difference in logged data
warning messages needed a change
instead of toplevel values, only the sub-object is affected
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants