Skip to content

Commit

Permalink
Removed pytest fixed version. Improved mocking in the test.
Browse files Browse the repository at this point in the history
  • Loading branch information
olegpidsadnyi committed Mar 22, 2016
1 parent 3132287 commit 073884f
Show file tree
Hide file tree
Showing 10 changed files with 105 additions and 20 deletions.
6 changes: 6 additions & 0 deletions CHANGES.rst
@@ -1,6 +1,12 @@
Changelog
=========

1.3.9
-----

- pytest fixed version number is removed from the requirements (olegpidsadnyi)
- removed pytest-cache dependency (olegpidsadnyi)

1.3.8
-----

Expand Down
4 changes: 3 additions & 1 deletion pytest_cloud/__init__.py
@@ -1 +1,3 @@
__version__ = '1.3.8'
"""PyTest Cloud."""

__version__ = '1.3.9'
1 change: 1 addition & 0 deletions pytest_cloud/patches.py
@@ -1,4 +1,5 @@
"""Monkey patches."""

import os
import xdist
from xdist import slavemanage
Expand Down
11 changes: 5 additions & 6 deletions pytest_cloud/plugin.py
Expand Up @@ -3,8 +3,9 @@
Provides an easy way of running tests amoung several test nodes (slaves).
"""
from __future__ import division

import argparse
import timeout_decorator
import sys

try:
from itertools import filterfalse # pylint: disable=E0611
Expand All @@ -13,13 +14,13 @@
from itertools import chain
import math
import os.path
import sys

import timeout_decorator

import execnet
from xdist.slavemanage import (
NodeManager,
)
from pytest_cache import getrootdir
import six

import pytest
Expand All @@ -29,7 +30,6 @@


class CloudXdistPlugin(object):

"""Plugin class to defer pytest-xdist hook handler."""


Expand All @@ -43,7 +43,6 @@ def pytest_configure(config):


class NodesAction(argparse.Action):

"""Parses out a space-separated list of nodes and extends dest with it."""

def __call__(self, parser, namespace, values, option_string=None):
Expand Down Expand Up @@ -237,7 +236,7 @@ def get_nodes_specs(
virtualenv_path = os.path.relpath(virtualenv_path)
node_specs = []
node_caps = {}
root_dir = getrootdir(config, '')
root_dir = config.rootdir
nodes = list(unique_everseen(nodes))
print('Detected root dir: {0}'.format(root_dir))
rsync = RSync(
Expand Down
2 changes: 1 addition & 1 deletion pytest_cloud/rsync.py
@@ -1,4 +1,5 @@
"""Faster rsync."""

import os
import tempfile
import subprocess
Expand All @@ -25,7 +26,6 @@ def make_reltoroot(roots, args):


class RSync(object):

"""Send a directory structure (recursively) to one or multiple remote filesystems."""

def __init__(
Expand Down
4 changes: 2 additions & 2 deletions requirements-testing.txt
@@ -1,7 +1,7 @@
coverage
mock<=1.0.1
mock
mysqlclient
pylama
pylama_pylint
pytest-pep8
astroid==1.3.6
astroid
2 changes: 1 addition & 1 deletion setup.py
Expand Up @@ -27,7 +27,7 @@
url='https://github.com/pytest-dev/pytest-cloud',
install_requires=[
'psutil',
'pytest<2.8.0',
'pytest',
'pytest-xdist',
'pytest-cache',
'setuptools',
Expand Down
1 change: 1 addition & 0 deletions tests/__init__.py
@@ -0,0 +1 @@
"""Tests."""
90 changes: 83 additions & 7 deletions tests/test_plugin.py
Expand Up @@ -4,9 +4,87 @@
import mock
import pytest

import xdist.dsession
import execnet
import pytest_cloud.plugin


PYTHON = 'python{0}.{1}'.format(*sys.version_info)


@pytest.fixture
def mocked_group(request):
"""Mocked execnet.Group."""
group = execnet.Group

def fin():
execnet.Group = group

mocked_group = mock.Mock()
request.addfinalizer(fin)
mocked_group.mkgateway.return_value = mock.Mock()
execnet.Group = mocked_group
return mocked_group


@pytest.fixture
def mocked_dsession(request):
"""Mocked xdist.dsession.DSession."""
dsession = xdist.dsession.DSession

def fin():
xdist.dsession.DSession = dsession

mocked_dsession = mock.Mock()
request.addfinalizer(fin)

def iterate():
yield
yield

def dic():
return {}

def rep():
class Report(object):
skipped = []
call = []
failed = []
result = []
passed = True
outcome = 'OK'
nodeid = 123
return Report()

mocked_dsession.return_value.pytest_addhooks = iterate
mocked_dsession.return_value.pytest_namespace = dic
mocked_dsession.return_value.pytest_addoption = iterate
mocked_dsession.return_value.pytest_configure = iterate
mocked_dsession.return_value.pytest_collectstart = iterate
mocked_dsession.return_value.pytest_make_collect_report = rep
mocked_dsession.return_value.pytest_collectreport = iterate
mocked_dsession.return_value.pytest_collection_modifyitems = iterate

xdist.dsession.DSession = mocked_dsession
return mocked_dsession


@pytest.fixture
def mocked_rsync(request):
"""Mocked pytest_cloud.plugin.RSync."""
rsync = pytest_cloud.plugin.RSync

def fin():
pytest_cloud.plugin.RSync = rsync

request.addfinalizer(fin)

mocked_rsync = mock.Mock()
pytest_cloud.plugin.RSync = mocked_rsync

return mocked_rsync


@pytest.mark.parametrize(
['host1', 'user1', 'cpu_count1', 'memory1', 'host2', 'user2', 'cpu_count2', 'memory2',
'mem_per_process', 'max_processes', 'result'],
Expand Down Expand Up @@ -51,18 +129,14 @@
]),
]
)
@mock.patch('xdist.dsession.DSession')
@mock.patch('execnet.Group')
@mock.patch('pytest_cloud.plugin.RSync')
def test_schedule(
mocked_rsync, mocked_group, mocked_dsession, testdir, host1, host2, user1, user2, cpu_count1,
mocked_dsession, mocked_group, mocked_rsync, testdir, host1, host2, user1, user2, cpu_count1,
cpu_count2, memory1, memory2, mem_per_process, max_processes, result, request):
"""Test scheduling of tests on given nodes."""
ch1 = mock.Mock()
ch1.gateway.id = host1
ch2 = mock.Mock()
ch2.gateway.id = host2
mocked_group.mkgateway.return_value = mock.Mock()

node1 = user1 + '@' + host1 if user1 else host1
node2 = user2 + '@' + host2 if user2 else host2
Expand All @@ -72,8 +146,10 @@ def test_schedule(
(ch2, {'cpu_count': cpu_count2, 'virtual_memory': {'available': memory2 * 1024 ** 2}}),
]
params = [
'--cloud-nodes={0}'.format(node1), '--cloud-node={0}'.format(node2),
'--cloud-chdir=test']
'--cloud-nodes={0}'.format(node1),
'--cloud-node={0}'.format(node2),
'--cloud-chdir=test',
]
if mem_per_process:
params.append('--cloud-mem-per-process={0}'.format(mem_per_process))
if max_processes:
Expand Down
4 changes: 2 additions & 2 deletions tox.ini
Expand Up @@ -8,7 +8,7 @@ commands= py.test tests --junitxml={envlogdir}/junit-{envname}.xml
deps =
-e.
-r{toxinidir}/requirements-testing.txt
passenv = DISPLAY COVERALLS_REPO_TOKEN USER PWD
passenv = DISPLAY TRAVIS TRAVIS_JOB_ID TRAVIS_BRANCH COVERALLS_REPO_TOKEN USER PWD

[testenv:linters]
basepython=python2.7
Expand Down Expand Up @@ -37,7 +37,7 @@ addopts = -vvl
format = pep8
skip = */.tox/*,*/.env/*
linters = pylint,mccabe,pep8,pep257
ignore = F0401,C0111,E731,D100,W0621,W0108,R0201,W0401,W0614,W0212,C901,R0914,I0011,C0325
ignore = F0401,C0111,E731,D100,W0621,W0108,R0201,W0401,W0614,W0212,C901,R0914,I0011,C0325,D203

[pylama:pep8]
max_line_length = 120
Expand Down

0 comments on commit 073884f

Please sign in to comment.