Skip to content

Commit

Permalink
Relative file paths, so that .testmondata can be moved/shared.
Browse files Browse the repository at this point in the history
  • Loading branch information
tarpas committed Dec 7, 2016
1 parent c872041 commit f533c2a
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
4 changes: 2 additions & 2 deletions test/test_testmon.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def func():

deps = track_it(testdir, func)

assert {os.path.abspath(a.strpath):
assert {os.path.relpath(a.strpath, testdir.tmpdir.strpath):
checksum_coverage(Module(file_name=a.strpath).blocks, [2])} == deps


Expand Down Expand Up @@ -143,7 +143,7 @@ def f():
coveragetest.import_local_file('a')

deps = track_it(testdir, f)
assert a.strpath in deps
assert os.path.relpath(a.strpath, testdir.tmpdir.strpath) in deps
assert len(deps) == 1

del sys.modules['a']
Expand Down
6 changes: 2 additions & 4 deletions testmon/pytest_testmon.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,7 @@ def __init__(self, config, testmon_data):
self.lastfailed = self.testmon_data.lastfailed

def pytest_report_header(self, config):
changed_files = ",".join([os.path.relpath(path, config.rootdir.strpath)
for path
in self.testmon_data.changed_files])
changed_files = ",".join(self.testmon_data.changed_files)
if changed_files == '' or len(changed_files) > 100:
changed_files = len(self.testmon_data.changed_files)
active_message = "testmon={}, changed files: {}, skipping collection of {} items".format(
Expand Down Expand Up @@ -166,7 +164,7 @@ def __init__(self, config):
self.config = config

def pytest_ignore_collect(self, path, config):
strpath = path.strpath
strpath = os.path.relpath(path.strpath, config.rootdir.strpath)
if strpath in self.testmon_data.unaffected_files:
if os.path.split(strpath)[1].startswith('test_'):
config.hook.pytest_deselected(
Expand Down
12 changes: 7 additions & 5 deletions testmon/testmon_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,14 +256,15 @@ def file_data(self):
def get_nodedata(self, nodeid, coverage_data, rootdir):
result = {}
for filename in coverage_data.measured_files():
relfilename = os.path.relpath(filename, rootdir)
lines = coverage_data.lines(filename)
if os.path.exists(filename):
result[filename] = checksum_coverage(self.parse_file(filename).blocks, lines)
result[relfilename] = checksum_coverage(self.parse_file(relfilename).blocks, lines)
if not result: # when testmon kicks-in the test module is already imported. If the test function is skipped
# coverage_data is empty. However, we need to write down, that we depend on the
# file where the test is stored (so that we notice e.g. when the test is no longer skipped.)
filename = os.path.join(rootdir, nodeid).split("::", 1)[0]
result[filename] = checksum_coverage(self.parse_file(filename).blocks, [1])
relfilename = os.path.relpath(os.path.join(rootdir, nodeid).split("::", 1)[0], self.rootdir)
result[relfilename] = checksum_coverage(self.parse_file(relfilename).blocks, [1])
return result

def set_dependencies(self, nodeid, nodedata):
Expand All @@ -276,9 +277,10 @@ def set_dependencies(self, nodeid, nodedata):
self.write_db(con, filename, nodeid, nodedata[filename])

def parse_file(self, file, new_mtime=None):
assert file[0] != '/'
if file not in self.changed_files:
self.changed_files[file] = Module(file_name=file)
self.changed_mtimes[file] = new_mtime if new_mtime else os.path.getmtime(file)
self.changed_files[file] = Module(file_name=os.path.join(self.rootdir, file))
self.changed_mtimes[file] = new_mtime if new_mtime else os.path.getmtime(os.path.join(self.rootdir, file))

return self.changed_files[file]

Expand Down

0 comments on commit f533c2a

Please sign in to comment.