Skip to content

Commit c36dc97

Browse files
authored
Rename host and port arguments for GRID (#253)
1 parent 2a7942d commit c36dc97

File tree

5 files changed

+84
-18
lines changed

5 files changed

+84
-18
lines changed

docs/user_guide.rst

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -248,11 +248,11 @@ driver, as the accepted capabilities may differ::
248248
pytest --driver Remote --capability browserName firefox
249249

250250
Note that if your server is not running locally or is running on an alternate
251-
port you will need to specify the ``--host`` and ``--port`` command line
251+
port you will need to specify the ``--selenium-host`` and ``--selenium-port`` command line
252252
options, or by setting the ``SELENIUM_HOST`` and ``SELENIUM_PORT`` environment
253253
variables::
254254

255-
pytest --driver Remote --host selenium.hostname --port 5555 --capability browserName firefox
255+
pytest --driver Remote --selenium-host selenium.hostname --selenium-port 5555 --capability browserName firefox
256256

257257
Sauce Labs
258258
----------
@@ -428,7 +428,7 @@ Local tunnel
428428
~~~~~~~~~~~~
429429

430430
To run the tests using `TestingBot's local tunnel <https://testingbot.com/support/other/tunnel>`_
431-
you'll also need to set the ``--host`` and ``--port`` command line arguments.
431+
you'll also need to set the ``--selenium-host`` and ``--selenium-port`` command line arguments.
432432

433433
CrossBrowserTesting
434434
-------------------
@@ -493,11 +493,11 @@ selection is determined using capabilities. Check the
493493
for details of accepted values.
494494

495495
Note that if your Appium server is not running locally or is running on an
496-
alternate port you will need to specify the ``--host`` and ``--port``
496+
alternate port you will need to specify the ``--selenium-host`` and ``--selenium-port``
497497
command line options, or by setting the ``APPIUM_HOST`` and ``APPIUM_PORT``
498498
environment variables::
499499

500-
pytest --driver Appium --host appium.hostname --port 5555
500+
pytest --driver Appium --selenium-host appium.hostname --selenium-port 5555
501501

502502
Specifying Capabilities
503503
***********************

pytest_selenium/pytest_selenium.py

Lines changed: 44 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
from .utils import CaseInsensitiveDict
1919
from . import drivers
2020

21+
import warnings
22+
2123
LOGGER = logging.getLogger(__name__)
2224

2325
SUPPORTED_DRIVERS = CaseInsensitiveDict(
@@ -162,8 +164,8 @@ def driver_kwargs(
162164
firefox_options=firefox_options,
163165
firefox_profile=firefox_profile,
164166
edge_options=edge_options,
165-
host=pytestconfig.getoption("host"),
166-
port=pytestconfig.getoption("port"),
167+
host=pytestconfig.getoption("selenium_host"),
168+
port=pytestconfig.getoption("selenium_port"),
167169
service_log_path=None,
168170
request=request,
169171
test=".".join(split_class_and_test_names(request.node.nodeid)),
@@ -228,6 +230,22 @@ def selenium(driver):
228230

229231
@pytest.hookimpl(trylast=True)
230232
def pytest_configure(config):
233+
if config.getoption("host"):
234+
warnings.warn(
235+
"--host has been deprecated and will be removed in a "
236+
"future release. Please use --selenium-host instead.",
237+
DeprecationWarning,
238+
)
239+
config.option.selenium_host = config.getoption("host")
240+
241+
if config.getoption("port"):
242+
warnings.warn(
243+
"--port has been deprecated and will be removed in a "
244+
"future release. Please use --selenium-port instead.",
245+
DeprecationWarning,
246+
)
247+
config.option.selenium_port = config.getoption("port")
248+
231249
capabilities = config._variables.get("capabilities", {})
232250
capabilities.update({k: v for k, v in config.getoption("capabilities")})
233251
config.addinivalue_line(
@@ -241,9 +259,9 @@ def pytest_configure(config):
241259
if hasattr(config, "_metadata"):
242260
config._metadata["Driver"] = config.getoption("driver")
243261
config._metadata["Capabilities"] = capabilities
244-
if all((config.getoption("host"), config.getoption("port"))):
262+
if all((config.option.selenium_host, config.option.selenium_port)):
245263
config._metadata["Server"] = "{0}:{1}".format(
246-
config.getoption("host"), config.getoption("port")
264+
config.option.selenium_host, config.option.selenium_port
247265
)
248266
config._capabilities = capabilities
249267

@@ -395,8 +413,12 @@ def __call__(self, parser, namespace, values, option_string=None):
395413
setattr(namespace, self.dest, values)
396414
driver = getattr(drivers, values.lower())
397415
# set the default host and port if specified in the driver module
398-
namespace.host = namespace.host or getattr(driver, "HOST", None)
399-
namespace.port = namespace.port or getattr(driver, "PORT", None)
416+
namespace.selenium_host = namespace.selenium_host or getattr(
417+
driver, "HOST", None
418+
)
419+
namespace.selenium_port = namespace.selenium_port or getattr(
420+
driver, "PORT", None
421+
)
400422

401423

402424
def pytest_addoption(parser):
@@ -453,14 +475,29 @@ def pytest_addoption(parser):
453475
group._addoption(
454476
"--host",
455477
metavar="str",
456-
help="host that the selenium server is listening on, "
478+
help="DEPRECATED host that the selenium server is listening on, "
457479
"which will default to the cloud provider default "
458480
"or localhost.",
459481
)
460482
group._addoption(
461483
"--port",
462484
type=int,
463485
metavar="num",
486+
help="DEPRECATED port that the selenium server is listening on, "
487+
"which will default to the cloud provider default "
488+
"or localhost.",
489+
)
490+
group._addoption(
491+
"--selenium-host",
492+
metavar="str",
493+
help="host that the selenium server is listening on, "
494+
"which will default to the cloud provider default "
495+
"or localhost.",
496+
)
497+
group._addoption(
498+
"--selenium-port",
499+
type=int,
500+
metavar="num",
464501
help="port that the selenium server is listening on, "
465502
"which will default to the cloud provider default "
466503
"or localhost.",

testing/test_driver.py

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,11 @@ def test_pass(driver_kwargs):
106106
testdir.quick_qa("--driver", "Remote", file_test, passed=1)
107107

108108

109-
def test_arguments_order(testdir):
109+
@pytest.mark.parametrize(
110+
("host_arg_name", "port_arg_name"),
111+
[("--selenium-host", "--selenium-port"), ("--host", "--port")],
112+
)
113+
def test_arguments_order(testdir, host_arg_name, port_arg_name):
110114
host = "notlocalhost"
111115
port = "4441"
112116
file_test = testdir.makepyfile(
@@ -120,7 +124,14 @@ def test_pass(driver_kwargs):
120124
)
121125
)
122126
testdir.quick_qa(
123-
"--driver", "Remote", "--host", host, "--port", port, file_test, passed=1
127+
"--driver",
128+
"Remote",
129+
host_arg_name,
130+
host,
131+
port_arg_name,
132+
port,
133+
file_test,
134+
passed=1,
124135
)
125136

126137

@@ -138,7 +149,14 @@ def test_pass(driver_kwargs):
138149
)
139150
)
140151
testdir.quick_qa(
141-
"--host", host, "--driver", "Remote", "--port", port, file_test, passed=1
152+
"--selenium-host",
153+
host,
154+
"--driver",
155+
"Remote",
156+
"--selenium-port",
157+
port,
158+
file_test,
159+
passed=1,
142160
)
143161

144162

testing/test_metadata.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,11 @@ def test_pass(metadata):
2323
testdir.quick_qa("--driver", "Remote", file_test, passed=1)
2424

2525

26-
def test_metadata_host_port(testdir):
26+
@pytest.mark.parametrize(
27+
("host_arg_name", "port_arg_name"),
28+
[("--selenium-host", "--selenium-port"), ("--host", "--port")],
29+
)
30+
def test_metadata_host_port(testdir, host_arg_name, port_arg_name):
2731
host = "notlocalhost"
2832
port = "4441"
2933
file_test = testdir.makepyfile(
@@ -37,5 +41,12 @@ def test_pass(metadata):
3741
)
3842
)
3943
testdir.quick_qa(
40-
"--driver", "Remote", "--host", host, "--port", port, file_test, passed=1
44+
"--driver",
45+
"Remote",
46+
host_arg_name,
47+
host,
48+
port_arg_name,
49+
port,
50+
file_test,
51+
passed=1,
4152
)

testing/test_testingbot.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ def test_invalid_credentials_file(failure, monkeypatch, tmpdir):
8585
def test_invalid_host(failure, monkeypatch, tmpdir):
8686
monkeypatch.setattr(os.path, "expanduser", lambda p: str(tmpdir))
8787
tmpdir.join(".testingbot").write("[credentials]\nkey=foo\nsecret=bar")
88-
out = failure("--host", "foo.bar.com")
88+
out = failure("--selenium-host", "foo.bar.com")
8989
messages = [
9090
"nodename nor servname provided, or not known",
9191
"Name or service not known",

0 commit comments

Comments
 (0)