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

Question: Why don't use base_url param value from pytest.ini when running with pytest-xdist? #34

Closed
grandfa8 opened this issue Jul 27, 2022 · 11 comments

Comments

@grandfa8
Copy link

grandfa8 commented Jul 27, 2022

Hi,
Thats not critical issue for me but it still interest.
Why we don't read base_url param value from pytest.ini when run tests with pytest-xdist plugin?
I try replace line https://github.com/pytest-dev/pytest-base-url/blob/master/src/pytest_base_url/plugin.py#L14
by
base_url = config.getoption("base_url") or config.getini("base_url") and this worked for me

@RonnyPfannschmidt
Copy link
Member

def pytest_configure(config):
if hasattr(config, "workerinput"):
return # don't run configure on xdist worker nodes
base_url = config.getoption("base_url") or config.getini("base_url")
if base_url is not None:
config.option.base_url = base_url
if hasattr(config, "_metadata"):
config._metadata["Base URL"] = base_url

this seems to be intended to set up the details, as far as i understood that works as intended

@phnmn
Copy link

phnmn commented Jul 27, 2022

if hasattr(config, "workerinput"): 
         return  # don't run configure on xdist worker nodes

Why was the base_url not instantiated for the xdist workers configuration?
Test runs on workers, not on the controller node, and they don't have this option from ini file.

@RonnyPfannschmidt
Copy link
Member

the options are passed by pytest from the controller to the worker

the configure hook sets the option

@phnmn
Copy link

phnmn commented Jul 27, 2022

starting pytest-xdist==1.30.0(Oct 1, 2019) base_url is not shared between controller and workers.

this changed in https://github.com/pytest-dev/pytest-xdist/blob/30b540cd1f70266fbb88883407a9b85dff0e1cb0/src/xdist/workermanage.py#L244
gets empty option_dict instead option_dict = vars(self.config.option)

@RonnyPfannschmidt
Copy link
Member

Good catch

@phnmn
Copy link

phnmn commented Jul 28, 2022

pytest-dev/pytest-xdist#800

@BeyondEvil
Copy link
Contributor

Closing this as it seems to be out-of-scope for this plugin. Feel free to reopen if you think otherwise.

@sayurionishi
Copy link

sayurionishi commented Sep 11, 2023

Hi @RonnyPfannschmidt @BeyondEvil, I have the same question with the issue title.
I always get an error on one of my pages as the base_url becomes None when running in parallel. My apologies, just asking for better understanding and best workaround for this issue.
TypeError: unsupported operand type(s) for +: 'NoneType' and 'str'

def load(self, base_url):
     self.page.goto(base_url + self.URL)
#pytest.ini
[pytest]
base_url = http://localhost:3000

It works though when passing the URL as an argument
pytest --base-url http://localhost:3000

@BeyondEvil
Copy link
Contributor

BeyondEvil commented Sep 11, 2023

There's a workaround if you follow the link to the (still open) issue over at pytest-xdist: #34 (comment). @sayurionishi

@sayurionishi
Copy link

Yes, saw this thread when searching for this issue. Thanks @BeyondEvil

@RonnyPfannschmidt
Copy link
Member

This one is a longstanding pytest bug thats hard to unravel

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

5 participants