From 6be2136f20c076b98b63233a701493c79acd7c6c Mon Sep 17 00:00:00 2001 From: Zac-HD Date: Wed, 26 Sep 2018 22:02:14 +1000 Subject: [PATCH 1/2] Ensure user_properties is a list --- AUTHORS | 5 +++-- changelog/4034.bugfix.rst | 3 +++ src/_pytest/reports.py | 7 ++++++- 3 files changed, 12 insertions(+), 3 deletions(-) create mode 100644 changelog/4034.bugfix.rst diff --git a/AUTHORS b/AUTHORS index a6562382012..2be74441a27 100644 --- a/AUTHORS +++ b/AUTHORS @@ -10,6 +10,7 @@ Ahn Ki-Wook Alan Velasco Alexander Johnson Alexei Kozlenok +Allan Feldman Anatoly Bubenkoff Anders Hovmöller Andras Tim @@ -179,6 +180,7 @@ Raphael Pierzina Raquel Alegre Ravi Chandra Roberto Polli +Roland Puntaier Romain Dorgueil Roman Bolshakov Ronny Pfannschmidt @@ -223,6 +225,5 @@ Wim Glenn Wouter van Ackooy Xuan Luong Xuecong Liao +Zac Hatfield-Dodds Zoltán Máté -Roland Puntaier -Allan Feldman diff --git a/changelog/4034.bugfix.rst b/changelog/4034.bugfix.rst new file mode 100644 index 00000000000..44044fb29e8 --- /dev/null +++ b/changelog/4034.bugfix.rst @@ -0,0 +1,3 @@ +The ``.user_properties`` attribute of ``TestReport`` objects is a list +of (name, value) tuples, but could sometimes be instantiated as a tuple +of tuples. It is now always a list. diff --git a/src/_pytest/reports.py b/src/_pytest/reports.py index 33b906702b8..4d4ab2f1746 100644 --- a/src/_pytest/reports.py +++ b/src/_pytest/reports.py @@ -110,7 +110,7 @@ def __init__( when, sections=(), duration=0, - user_properties=(), + user_properties=None, **extra ): #: normalized collection node id @@ -136,6 +136,11 @@ def __init__( #: user properties is a list of tuples (name, value) that holds user #: defined properties of the test + if user_properties is None: + user_properties = [] + elif not isinstance(user_properties, list): + # This used to be a tuple; so cast for backwards-compatibility + user_properties = list(user_properties) self.user_properties = user_properties #: list of pairs ``(str, str)`` of extra information which needs to From a089a9577ea850f0bcf822cf2c666490a62200d0 Mon Sep 17 00:00:00 2001 From: Zac-HD Date: Wed, 26 Sep 2018 22:40:11 +1000 Subject: [PATCH 2/2] Succinct definition of user_properties --- src/_pytest/reports.py | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/_pytest/reports.py b/src/_pytest/reports.py index 4d4ab2f1746..a57c9fa80b9 100644 --- a/src/_pytest/reports.py +++ b/src/_pytest/reports.py @@ -136,12 +136,7 @@ def __init__( #: user properties is a list of tuples (name, value) that holds user #: defined properties of the test - if user_properties is None: - user_properties = [] - elif not isinstance(user_properties, list): - # This used to be a tuple; so cast for backwards-compatibility - user_properties = list(user_properties) - self.user_properties = user_properties + self.user_properties = list(user_properties or []) #: list of pairs ``(str, str)`` of extra information which needs to #: marshallable. Used by pytest to add captured text