Skip to content

Commit

Permalink
Tracking setup/call/teardown instead of only call, fixes #17
Browse files Browse the repository at this point in the history
  • Loading branch information
tarpas committed Jun 5, 2015
1 parent 7a21e05 commit ccc4088
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 21 deletions.
1 change: 1 addition & 0 deletions exampleproject/tests_2/pytest.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[pytest]
5 changes: 5 additions & 0 deletions exampleproject/tests_2/test_e.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import pytest

@pytest.mark.skipif(True, reason="Because")
def test_1():
pass
2 changes: 1 addition & 1 deletion test/test_testmon.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def track_it(testdir, func):
testmon_data = TestmonData(testdir.tmpdir.strpath)
_result, coverage_data = testmon.track_dependencies(func, 'testnode')

testmon_data.set_dependencies('testnode', coverage_data)
testmon_data.set_dependencies('testnode', coverage_data, testdir.tmpdir.strpath)
return testmon_data.node_data['testnode']


Expand Down
22 changes: 11 additions & 11 deletions testmon/pytest_testmon.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,11 @@ def pytest_collection_modifyitems(self, session, config, items):
if deselected:
config.hook.pytest_deselected(items=deselected)

def pytest_runtest_call(self, __multicall__, item):
def pytest_runtest_protocol(self, __multicall__, item, nextitem):
if self.config.getoption('testmon') == u'readonly':
return __multicall__.execute()
result, coverage_data = self.testmon.track_dependencies(__multicall__.execute, item.nodeid)
self.testmon_data.set_dependencies(item.nodeid, coverage_data)
self.testmon_data.set_dependencies(item.nodeid, coverage_data, item.config.rootdir.strpath)

return result

Expand All @@ -158,15 +158,15 @@ def pytest_runtest_logreport(self, report):
pass

def pytest_ignore_collect(self, path, config):
affected, unaffected = config.testmon_data.file_affects(config.rootdir.strpath,
path.strpath)
if affected:
return False
if len(unaffected)==0:
return False
else:
config.hook.pytest_deselected(items=unaffected)
return True
if path.strpath.endswith('.py'):
affected, unaffected = config.testmon_data.file_affects(path.strpath)
if affected:
return False
if len(unaffected)==0:
return False
else:
config.hook.pytest_deselected(items=unaffected)
return True

def pytest_internalerror(self, excrepr, excinfo):
self.testmon_save = False
Expand Down
22 changes: 13 additions & 9 deletions testmon/testmon_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,11 @@ def get_variant_inifile(inifile):

class TestmonData(object):

def __init__(self, directory, variant=None):
def __init__(self, rootdir, variant=None):

self.variant = variant if variant else 'default'
self.init_connection(directory)
self.rootdir = rootdir
self.init_connection()
self.mtimes = {}
self.node_data = {}
self.modules_cache = {}
Expand All @@ -149,8 +150,8 @@ def __eq__(self, other):
def is_unchanged(self):
return (not self.affected and not self.newfile and not self.lastfailed and len(self.node_data)>0)

def init_connection(self, directory):
self.datafile = os.path.join(directory, '.testmondata')
def init_connection(self):
self.datafile = os.path.join(self.rootdir, '.testmondata')
self.connection = None
import sqlite3

Expand Down Expand Up @@ -223,17 +224,20 @@ def modules_test_counts(self):
test_counts[module] += 1
return test_counts

def set_dependencies(self, nodeid, coverage_data):
def set_dependencies(self, nodeid, coverage_data, rootdir):
result = {}
for filename, value in coverage_data.lines.items():
if os.path.exists(filename):
result[filename] = checksum_coverage(self.parse_cache(filename).blocks, value.keys())
if not result:
filename = os.path.join(rootdir, nodeid).split("::",1)[0]
result[filename] = checksum_coverage(self.parse_cache(filename).blocks,[1])
self.node_data[nodeid] = result

def parse_cache(self, module):
def parse_cache(self, module, new_mtime=None):
if module not in self.modules_cache:
self.modules_cache[module] = Module(file_name=module)
self.mtimes[module] = os.path.getmtime(module)
self.mtimes[module] = new_mtime if new_mtime else os.path.getmtime(module)

return self.modules_cache[module]

Expand Down Expand Up @@ -264,11 +268,11 @@ def compute_affected(self):
self.affected.add(nodeid)
self.unaffected = set(self.node_data.keys()) - self.affected

def file_affects(self, rootdir, path):
def file_affects(self, path):
affected = []
unaffected = []
for nodeid in self.node_data:
if os.path.join(rootdir, nodeid.split("::")[0]) == path:
if os.path.join(self.rootdir, nodeid.split("::")[0]) == path:
if self.test_should_run(nodeid) or nodeid in self.lastfailed:
affected.append(nodeid)
else:
Expand Down

0 comments on commit ccc4088

Please sign in to comment.