Skip to content

Commit

Permalink
Multiple fixes (#67)
Browse files Browse the repository at this point in the history
* Fix ambigous variable usage

Use of "l" caused linting failure.

* Fixed deprecation of getfuncargvalue

getfuncargvalue was deprecated in favour of getfixturevalue

* Remove use of deprecated pytest.config

Use standard pytest marks for slow tests instead.

* Fixed test failure with GILT_CACHE_DIRECTORY

Tests where failing when GILT_CACHE_DIRECTORY was not ending in '.gilt'.

* Fix tox failure due to use of relative path with --cov

Move py.test params to setup.cfg in order to make them available
to all pytest executions, regardless if they are run inside or ourside
tox.

This fixes problem where tox was failing to create coverage because
{toxinidir} was expanded to a relative path which is not supported
by pytest-cov.

By using the path mentioned in setup.cfg we avoid this issue as
in this case pytest-cov is able to generate the files.
  • Loading branch information
ssbarnea authored and retr0h committed Mar 5, 2019
1 parent 4d6aee1 commit 234eec2
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 18 deletions.
6 changes: 3 additions & 3 deletions test/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ def pytest_addoption(parser):
parser.addoption("--runslow", action="store_true", help="run slow tests")


def random_string(l=5):
return ''.join(random.choice(string.ascii_uppercase) for _ in range(l))
def random_string(len=5):
return ''.join(random.choice(string.ascii_uppercase) for _ in range(len))


@pytest.fixture()
Expand All @@ -56,7 +56,7 @@ def gilt_config_file(temp_dir, request):
fixture = request.param
d = temp_dir
c = d.join(os.extsep.join(('gilt', 'yml')))
c.write(request.getfuncargvalue(fixture))
c.write(request.getfixturevalue(fixture))

return c.strpath

Expand Down
11 changes: 6 additions & 5 deletions test/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,14 @@
def test_config(gilt_config_file):
result = config.config(gilt_config_file)
os_split = pytest.helpers.os_split
gilt_root = os.path.basename(config.BASE_WORKING_DIR)

r = result[0]
assert 'https://github.com/retr0h/ansible-etcd.git' == r.git
assert 'master' == r.version
assert 'retr0h.ansible-etcd' == r.name
assert ('.gilt', 'clone', 'retr0h.ansible-etcd') == os_split(r.src)[-3:]
assert ('.gilt', 'lock',
assert (gilt_root, 'clone', 'retr0h.ansible-etcd') == os_split(r.src)[-3:]
assert (gilt_root, 'lock',
'retr0h.ansible-etcd') == os_split(r.lock_file)[-3:]
assert ('roles', 'retr0h.ansible-etcd', '') == os_split(r.dst)[-3:]
assert [] == r.files
Expand All @@ -51,7 +52,7 @@ def test_config(gilt_config_file):
assert r.dst is None

f = r.files[0]
x = ('.gilt', 'clone', 'lorin.openstack-ansible-modules', '*_manage')
x = (gilt_root, 'clone', 'lorin.openstack-ansible-modules', '*_manage')
assert x == os_split(f.src)[-4:]
assert ('library', '') == os_split(f.dst)[-2:]

Expand Down Expand Up @@ -189,8 +190,8 @@ def test_get_dst_dir(temp_dir):

def test_get_clone_dir():
parts = pytest.helpers.os_split(config._get_clone_dir())

assert ('.gilt', 'clone') == parts[-2:]
gilt_root = os.path.basename(config.BASE_WORKING_DIR)
assert (gilt_root, 'clone') == parts[-2:]


def test_makedirs(temp_dir):
Expand Down
14 changes: 5 additions & 9 deletions test/test_git.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,8 @@

from gilt import git

slow = pytest.mark.skipif(
not pytest.config.getoption("--runslow"),
reason="need --runslow option to run")


@slow
@pytest.mark.slow
def test_clone(temp_dir):
name = 'retr0h.ansible-etcd'
repo = 'https://github.com/retr0h/ansible-etcd.git'
Expand All @@ -44,7 +40,7 @@ def test_clone(temp_dir):
assert os.path.exists(destination)


@slow
@pytest.mark.slow
def test_extract(temp_dir):
name = 'retr0h.ansible-etcd'
repo = 'https://github.com/retr0h/ansible-etcd.git'
Expand All @@ -68,7 +64,7 @@ def test_extract(temp_dir):
assert os.path.exists(giltfile)


@slow
@pytest.mark.slow
def test_overlay(mocker, temp_dir):
name = 'lorin.openstack-ansible-modules'
repo = 'https://github.com/lorin/openstack-ansible-modules.git'
Expand Down Expand Up @@ -99,7 +95,7 @@ def test_overlay(mocker, temp_dir):
assert 2 == len(glob.glob('{}/*'.format(os.path.join(dst_dir, 'tests'))))


@slow
@pytest.mark.slow
def test_overlay_existing_directory(mocker, temp_dir):
name = 'lorin.openstack-ansible-modules'
repo = 'https://github.com/lorin/openstack-ansible-modules.git'
Expand Down Expand Up @@ -208,7 +204,7 @@ def test_get_version_needs_pull(mocker, patched_run_command):
assert expected == patched_run_command.mock_calls


@slow
@pytest.mark.slow
def test_has_version(temp_dir):
name = 'retr0h.ansible-etcd'
repo = 'https://github.com/retr0h/ansible-etcd.git'
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ deps =
-rrequirements.txt
-rtest-requirements.txt
commands =
unit: py.test --runslow -vv --cov-report=term-missing --cov={toxinidir}/gilt/ --no-cov-on-fail {posargs}
unit: py.test --runslow -vv {posargs}
lint: flake8

[testenv:format]
Expand Down

0 comments on commit 234eec2

Please sign in to comment.