Skip to content

Commit

Permalink
Fix command line argument ordering issue
Browse files Browse the repository at this point in the history
Fixes #142
  • Loading branch information
Jim Brännlund authored and davehunt committed Dec 5, 2017
1 parent 0777138 commit 453a0e3
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 2 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,8 @@ __pycache__
.eggs
build
dist
<<<<<<< HEAD
Pipfile*
=======
*Pipfile*
>>>>>>> 6bda4e8... Fix command line argument ordering issue
4 changes: 2 additions & 2 deletions pytest_selenium/pytest_selenium.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,8 +290,8 @@ def __call__(self, parser, namespace, values, option_string=None):
setattr(namespace, self.dest, values)
driver = getattr(drivers, values.lower())
# set the default host and port if specified in the driver module
setattr(namespace, 'host', getattr(driver, 'HOST', None))
setattr(namespace, 'port', getattr(driver, 'PORT', None))
namespace.host = namespace.host or getattr(driver, 'HOST', None)
namespace.port = namespace.port or getattr(driver, 'PORT', None)


def pytest_addoption(parser):
Expand Down
42 changes: 42 additions & 0 deletions testing/test_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,45 @@ def test_driver_quit(selenium):
'WARNING: Failed to gather log types: *'])
outcomes = result.parseoutcomes()
assert outcomes.get('failed') == 1


def test_default_host_port(testdir):
host = 'localhost'
port = 4444
file_test = testdir.makepyfile("""
import pytest
@pytest.mark.nondestructive
def test_pass(driver_kwargs):
assert driver_kwargs['command_executor'] == 'http://{}:{}/wd/hub'
""".format(host, port))
testdir.quick_qa('--driver', 'Remote', file_test, passed=1)


def test_arguments_order(testdir):
host = 'notlocalhost'
port = 4441
file_test = testdir.makepyfile("""
import pytest
@pytest.mark.nondestructive
def test_pass(driver_kwargs):
assert driver_kwargs['command_executor'] == 'http://{}:{}/wd/hub'
""".format(host, port))
testdir.quick_qa('--driver', 'Remote',
'--host', host,
'--port', port,
file_test, passed=1)


def test_arguments_order_random(testdir):
host = 'notlocalhost'
port = 4441
file_test = testdir.makepyfile("""
import pytest
@pytest.mark.nondestructive
def test_pass(driver_kwargs):
assert driver_kwargs['command_executor'] == 'http://{}:{}/wd/hub'
""".format(host, port))
testdir.quick_qa('--host', host,
'--driver', 'Remote',
'--port', port,
file_test, passed=1)
34 changes: 34 additions & 0 deletions testing/test_metadata.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.

import pytest

pytestmark = pytest.mark.nondestructive


def test_metadata_default_host_port(testdir):
host = 'localhost'
port = 4444
file_test = testdir.makepyfile("""
import pytest
@pytest.mark.nondestructive
def test_pass(metadata):
assert metadata['Server'] == '{}:{}'
""".format(host, port))
testdir.quick_qa('--driver', 'Remote', file_test, passed=1)


def test_metadata_host_port(testdir):
host = 'notlocalhost'
port = 4441
file_test = testdir.makepyfile("""
import pytest
@pytest.mark.nondestructive
def test_pass(metadata):
assert metadata['Server'] == '{}:{}'
""".format(host, port))
testdir.quick_qa('--driver', 'Remote',
'--host', host,
'--port', port,
file_test, passed=1)

0 comments on commit 453a0e3

Please sign in to comment.