Skip to content

urllib : TypeError: Cannot mix str and non-str arguments #311

Open
@vmonteco

Description

@vmonteco

I'm trying to get the most minimalist example possible to ensure my setup is correct.

Yet, when I try to run the following test file :

test_base.py :

from selenium import webdriver

def test_base():
    chrome_driver = webdriver.Chrome()
    chrome_driver.get("https://google.com/")

I get the following :

> pytest path/to/test_base.py
...
        url        = 'http://localhost:47883/session'
        urlopen_kw = {'body': '{"capabilities": {"firstMatch": [{}], "alwaysMatch": {"browserName": "chrome", "pageLoadStrategy": "normal", "goog:chromeOptions": {"extensions": [], "args": []}}}}', 'request_url': 'http://localhost:47883/session'}
../pythons/3.9.7/venv/lib/python3.9/site-packages/urllib3/poolmanager.py:382: in urlopen
    redirect_location = urljoin(url, redirect_location)
        conn       = <urllib3.connectionpool.HTTPConnectionPool object at 0x7f619c2788e0>
        kw         = {'assert_same_host': False, 'body': '{"capabilities": {"firstMatch": [{}], "alwaysMatch": {"browserName": "chrome", "p...ntent-Type': 'application/json;charset=UTF-8', 'User-Agent': 'selenium/4.10.0 (python linux)'}, 'redirect': False, ...}
        method     = 'POST'
        redirect   = True
        redirect_location = <MagicMock name='mock.get_redirect_location()' id='140057205906208'>
        response   = <MagicMock id='140057206275904'>
        self       = <urllib3.poolmanager.PoolManager object at 0x7f619c00a250>
        u          = Url(scheme='http', auth=None, host='localhost', port=47883, path='/session', query=None, fragment=None)
        url        = 'http://localhost:47883/session'
../pythons/3.9.7/lib/python3.9/urllib/parse.py:532: in urljoin
    base, url, _coerce_result = _coerce_args(base, url)
        allow_fragments = True
        base       = 'http://localhost:47883/session'
        url        = <MagicMock name='mock.get_redirect_location()' id='140057205906208'>
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

args = ('http://localhost:47883/session', <MagicMock name='mock.get_redirect_location()' id='140057205906208'>), str_input = True, arg = <MagicMock name='mock.get_redirect_location()' id='140057205906208'>

    def _coerce_args(*args):
        # Invokes decode if necessary to create str args
        # and returns the coerced inputs along with
        # an appropriate result coercion function
        #   - noop for str inputs
        #   - encoding function otherwise
        str_input = isinstance(args[0], str)
        for arg in args[1:]:
            # We special-case the empty string to support the
            # "scheme=''" default argument to some functions
            if arg and isinstance(arg, str) != str_input:
>               raise TypeError("Cannot mix str and non-str arguments")
E               TypeError: Cannot mix str and non-str arguments

arg        = <MagicMock name='mock.get_redirect_location()' id='140057205906208'>
args       = ('http://localhost:47883/session', <MagicMock name='mock.get_redirect_location()' id='140057205906208'>)
str_input  = True

../pythons/3.9.7/lib/python3.9/urllib/parse.py:125: TypeError

Here are the versions I use :
Python = 3.9.7
Pytest = 7.3.2
Pytest-selenium = 4.10

I also tried with and without the --driver parameter option for an identical result.

What did I get wrong on the pytest-selenium point of vier?

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