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

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

Open
vmonteco opened this issue Jun 14, 2023 · 1 comment
Open

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

vmonteco opened this issue Jun 14, 2023 · 1 comment

Comments

@vmonteco
Copy link

vmonteco commented Jun 14, 2023

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?

@BeyondEvil
Copy link
Contributor

From the example you provided, you're not using this plugin.

It should look like:

test_base.py

def test_base(driver):
    driver.get("https://google.com/")

Given you've passed in the --driver chrome argument to pytest.

Also, there's no 4.10 version of this plugin. Latest is 4.0.1.

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

2 participants