Skip to content

pytest-html is trying to encode my data inappropriately #27

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

Closed
birdsarah opened this issue Jan 25, 2016 · 5 comments
Closed

pytest-html is trying to encode my data inappropriately #27

birdsarah opened this issue Jan 25, 2016 · 5 comments

Comments

@birdsarah
Copy link

I'm using:

  • pytest-selenium 1.1
  • pytest-html 1.7
  • selenium 2.49.2

I get the following error on a test fail:

INTERNALERROR>     data = b64encode(content.encode(charset)).decode('ascii')
INTERNALERROR> AttributeError: 'bytes' object has no attribute 'encode'
> /Users/caged/miniconda3/envs/bokeh_34/lib/python3.4/site-packages/pytest_html-1.7-py3.4.egg/pytest_html/plugin.py(74)data_uri()
-> data = b64encode(content.encode(charset)).decode('ascii')


 72     def data_uri(content, mime_type='text/plain', charset='utf-8'):
 73         if PY3:
 74  ->         data = b64encode(content.encode(charset)).decode('ascii')
 75         else:
 76             data = b64encode(content)
 77         return 'data:{0};charset={1};base64,{2}'.format(mime_type, charset, data)

When in pdb, just running b64encode(content) works great - maybe PY3 check isn't quite right? Could we check what content is instead?

@davehunt
Copy link
Collaborator

@birdsarah could you paste more of your stack trace? I'm most interested in what content is, and where it's being provided. I assume this is one of the debug items from pytest-selenium but it's not clear which one. Note that pytest-selenium doesn't officially support Python 3.x, and it's possible it could be fixed there. That said, we probably want to support bytes objects in pytest-html too.

@davehunt
Copy link
Collaborator

I was able to replicate this, and have addressed it in #28. I am still interested in where this bytes object is being created though, if you could provide more information.

@davehunt
Copy link
Collaborator

My guess is that this is caused by pytest-selenium encoding here and here. This is necessary for Python 2.x but perhaps not for 3.x? @The-Compiler do you think this should be fixed in pytest-selenium to just pass the unicode object instead of encoding it first?

@The-Compiler
Copy link
Member

As per the "unicode sandwich" concept (decode/encode at the borders, deal with unicode everywhere else), I think that'd make sense, yeah.

@davehunt
Copy link
Collaborator

Closing as the content should be encoded properly before sending it to pytest-html. I'll be fixing this in pytest-selenium.

BeyondEvil added a commit that referenced this issue Mar 5, 2023
* fix main.js conflicts

* fix js test

* fix resource (main.js) test

* revert change to report extra

* filters style

* css and dom brush up

* Buildable app

* always store data in html

* Always store data blob in file

* json dump test data

* read data from dom element

* manually initialize state

* minimalistic dataset

* simplify included files

* Handle report extras

* Handle python report hooks

* imgviewer

* present name in image viewer and open img on click

* setup linter for project

* conform to styles

* show video in imageviewer (#14)

* show video in imageviewer

* Chore: Pluralize extra (#15)

* Add extras.HTML

* Move outcome handling to backend (#18)

* Move outcome handling to backend

* Pass in text version of longrepr if present

* make collapse/expand all functional (#20)

* make collapse/expand all functional

* only create links for text, url and json (#22)

* make filter search case insensitive (#21)

* make filter search case insensitive

* use sessionStorage to prevent preferences to be reapplied on new reports

* avoid multiple event bindings + fix filter bug

* Collapse individual row

Co-authored-by: Jim Brännlund <[email protected]>

* add no log output captured string

* Query params (#25)

* Add query params

* adjust tests (#26)

* Duration format (#27)

* adjust tests

* build format handler

* remove dependency

---------

Co-authored-by: Jim Brännlund <[email protected]>

* Beyondevil/cleanup (#28)

* chore: Cleanup branch before merge

* chore: Fix duration and CI

* Fix pre-commit issues

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Viktor Gustafsson <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants