pytest-dev / pytest-base-url

pytest plugin for URL based tests
Other
38 stars 11 forks source link

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

Closed grandfa8 closed 1 year ago

grandfa8 commented 2 years ago

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 commented 2 years ago

https://github.com/pytest-dev/pytest-base-url/blob/a88f70a4606e84ed69c1b7ce1f431ec321daf2b2/src/pytest_base_url/plugin.py#L36-L43

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

phnmn commented 2 years ago
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 commented 2 years ago

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

the configure hook sets the option

phnmn commented 2 years ago

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 commented 2 years ago

Good catch

phnmn commented 2 years ago

https://github.com/pytest-dev/pytest-xdist/issues/800

BeyondEvil commented 1 year ago

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

sayurionishi commented 1 year ago

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 commented 1 year ago

There's a workaround if you follow the link to the (still open) issue over at pytest-xdist: https://github.com/pytest-dev/pytest-base-url/issues/34#issuecomment-1198486693. @sayurionishi

sayurionishi commented 1 year ago

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

RonnyPfannschmidt commented 1 year ago

This one is a longstanding pytest bug thats hard to unravel