Skip to content

Support pathlib for attachment files #23

@zooba

Description

@zooba

def add_attachment(self, file, description):
r = self.nunit_xml.cases[self.id]
if r['attachments'] is None:
r['attachments'] = {}
r['attachments'][file] = description

Essentially, rewrite this to:

 def add_attachment(self, file, description): 
     r = self.nunit_xml.cases[self.id] 
     r.setdefault('attachments', {})[os.fsdecode(file)] = description 

(Threw in the setdefault for fun - you don't have to keep it ;) )

There are likely other places that will need similar updating, but I haven't reviewed it all yet. I'd recommend fsdecode if it's available, as that will get you to a str on all platforms, but if you're still supported older versions you'll need a stub like:

def fake_fsdecode(p):
    if isinstance(p, bytes_or_str_depending_on_python_version):
        return p.decode(os.getfsencoding())
    return str(p)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions