def track_it(testdir, func): testmon = Testmon(project_dirs=[testdir.tmpdir.strpath], testmon_labels=set()) testmon_data = TestmonData(testdir.tmpdir.strpath) _result, coverage_data = testmon.track_dependencies(func, 'testnode') testmon_data.set_dependencies('testnode', coverage_data, testdir.tmpdir.strpath) return testmon_data.node_data['testnode']
def init_testmon_data(config, read_source=True): if not hasattr(config, "testmon_data"): environment = eval_environment(config.getini("environment_expression")) testmon_data = TestmonData(config.rootdir.strpath, environment=environment) if read_source: testmon_data.determine_stable() config.testmon_data = testmon_data
def track_it(testdir, func): testmon = CoreTestmon(project_dirs=[testdir.tmpdir.strpath], testmon_labels=set()) testmon_data = CoreTestmonData(testdir.tmpdir.strpath) testmon_data.read_source() testmon.start() func() testmon.stop_and_save(testmon_data, testdir.tmpdir.strpath, 'testnode') return testmon_data._fetch_node_data()[0]['testnode']
def init_testmon_data(config): if not hasattr(config, 'testmon_data'): variant = eval_variant(config.getini('run_variant_expression')) config.project_dirs = config.getoption('project_directory') or [config.rootdir.strpath] testmon_data = TestmonData(config.project_dirs[0], variant=variant) affected = testmon_data.read_fs() config.testmon_data = testmon_data return affected
def test_affected_list(self): changes = {'test_a.py': [102, 103]} td = CoreTestmonData('') td.node_data = {'node1': {'test_a.py': [101, 102]}, 'node2': {'test_a.py': [102, 103], 'test_b.py': [200, 201]}} assert set(td.file_data()) == set(['test_a.py', 'test_b.py']) assert affected_nodeids(td.node_data, changes) == ['node1']
def init_testmon_data(config): if not hasattr(config, 'testmon_data'): variant = eval_variant(config.getini('run_variant_expression')) config.project_dirs = config.getoption('project_directory') or [ config.rootdir.strpath ] testmon_data = TestmonData(config.project_dirs[0], variant=variant) affected = testmon_data.read_fs() config.testmon_data = testmon_data return affected
def test_affected_list(self, testdir): changes = {'test_a.py': [102, 103]} td = CoreTestmonData(testdir.tmpdir.strpath) td.node_data = {'node1': {'test_a.py': [101, 102]}, 'node2': {'test_a.py': [102, 103], 'test_b.py': [200, 201]}} assert set(td.file_data()) == set(['test_a.py', 'test_b.py']) assert affected_nodeids(td.node_data, changes) == {'node1'}
def test_skipped(self, testdir): testdir.makepyfile(test_a=""" import pytest @pytest.mark.skip def test_add(): 1/0 """, ) testdir.inline_run("--testmon", "-v") testmon_data = CoreTestmonData(testdir.tmpdir.strpath) testmon_data.read_data() assert testmon_data.node_data['test_a.py::test_add']['test_a.py']
def test_write_read_data2(testdir): n1_node_data = {'a.py': [1]} td = CoreTestmonData(testdir.tmpdir.strpath, 'default') td.lastfailed = ['n1'] td.write_data() td.set_dependencies('n1', n1_node_data, ) td2 = CoreTestmonData(testdir.tmpdir.strpath, 'default') td2.read_data() assert td2.node_data['n1'] == n1_node_data
def test_write_read_data2(testdir): td = TestmonData(testdir.tmpdir.strpath, 'default') td.mtimes = {'a.py': 1.0} td.node_data = {'n1': {'a.py': [1]}} td.lastfailed = ['n1'] td.write_data() td2 = TestmonData(testdir.tmpdir.strpath, 'default') td2.read_data() assert td == td2
def init_testmon_data(config, read_source=True): if not hasattr(config, "testmon_data"): environment = config.getoption( "environment_expression") or eval_environment( config.getini("environment_expression")) libraries = ", ".join(sorted( str(p) for p in pkg_resources.working_set)) testmon_data = TestmonData(config.rootdir.strpath, environment=environment, libraries=libraries) if read_source: testmon_data.determine_stable() config.testmon_data = testmon_data
def test_write_read_data2(self, testdir): n1_node_data = {'test_a.py': [1]} td = CoreTestmonData(testdir.tmpdir.strpath, 'default') td.lastfailed = ['test_a.py::n1'] td.write_data() td.set_dependencies('test_a.py::n1', n1_node_data, {}) td2 = CoreTestmonData(testdir.tmpdir.strpath, 'default') td2.read_data() assert td2.node_data['test_a.py::n1'] == n1_node_data assert td2.f_tests['test_a.py'] == set(['test_a.py::n1'])
def test_collect_garbage(self, tmdata): tmdata.write("test_1", {"test_1.py": encode_lines(["FINGERPRINT1"])}) tmdata.source_tree.cache["test_1.py"] = Module(source_code="") tmdata.source_tree.cache["test_1.py"].mtime = 1100.0 tmdata.source_tree.cache["test_1.py"].checksum = 600 tmdata.source_tree.cache["test_1.py"].fingerprint = "FINGERPRINT2" tmdata.determine_stable() assert set(tmdata.all_nodes) tmdata.sync_db_fs_nodes(retain=set()) tmdata.close_connection() td2 = CoreTestmonData("") td2.determine_stable() assert set(td2.all_nodes) == set()
def test_wrong_result_processing(self, testdir): tf = testdir.makepyfile(test_a=""" def test_add(): 1/0 """, ) testdir.inline_run("--testmon", "-v") testmon_data = CoreTestmonData(testdir.tmpdir.strpath) testmon_data.read_data() assert len(testmon_data.fail_reports['test_a.py::test_add']) == 3 tf = testdir.makepyfile(test_a=""" import pytest @pytest.mark.skip def test_add(): 1/0/0 """, ) tf.setmtime(1) testdir.inline_run("--testmon", "-v") testmon_data.read_data() assert len(testmon_data.fail_reports['test_a.py::test_add']) == 0 tf = testdir.makepyfile(test_a=""" import pytest def test_add(): 1/0 """, ) tf.setmtime(2) testdir.inline_run("--testmon", "-v") testmon_data.read_data() assert len(testmon_data.fail_reports['test_a.py::test_add']) == 3
def test_skipped_under_dir(self, testdir): subdir = testdir.mkdir("tests") tf = subdir.join("test_a.py") tf.write(""" import pytest @pytest.mark.skip def test_add(): 1/0 """, ) tf.setmtime(1) testdir.inline_run("--testmon", "-v", "tests") testmon_data = CoreTestmonData(testdir.tmpdir.strpath) testmon_data.read_data() fname = os.path.sep.join(['tests', 'test_a.py']) assert testmon_data.node_data['tests/test_a.py::test_add'][fname]
def test_variants_separation(testdir): testmon1_data = CoreTestmonData(testdir.tmpdir.strpath, variant='1') testmon1_data.node_data['node1'] = {'a.py': 1} testmon1_data.write_data() testmon2_data = CoreTestmonData(testdir.tmpdir.strpath, variant='2') testmon2_data.node_data['node1'] = {'a.py': 2} testmon2_data.write_data() testmon_check_data = CoreTestmonData(testdir.tmpdir.strpath, variant='1') assert testmon1_data.node_data['node1'] == {'a.py': 1}
def test_write_read_data2(testdir): original = ({'a.py': 1.0}, {'n1': {'a.py': [1]}}, ['n1']) td = CoreTestmonData(testdir.tmpdir.strpath, 'default') td.mtimes, td.node_data, td.lastfailed = original td.write_data() td2 = CoreTestmonData(testdir.tmpdir.strpath, 'default') td2.read_data() assert original == (td2.mtimes, td2.node_data, td2.lastfailed)
def init_testmon_data(config, read_source=True): if not hasattr(config, 'testmon_data'): variant = eval_variant(config.getini('run_variant_expression')) config.project_dirs = config.getoption('project_directory') or [config.rootdir.strpath] testmon_data = TestmonData(config.project_dirs[0], variant=variant) testmon_data.read_data() if read_source: testmon_data.read_source() config.testmon_data = testmon_data
def test_write_read_data(testdir): td = CoreTestmonData(testdir.tmpdir.strpath, 'V1') with td.connection: td._write_attribute('1', {'a': 1}) td2 = CoreTestmonData(testdir.tmpdir.strpath, 'V1') assert td2._fetch_attribute('1') == {'a': 1}
def test_write_data(testdir): td = CoreTestmonData(testdir.tmpdir.strpath, 'V1') td._write_attribute('1', {})
def test_read_nonexistent(testdir): td = CoreTestmonData(testdir.tmpdir.strpath, 'V2') assert td._fetch_attribute('1') == None
def test_variants_separation(testdir): testmon1_data = CoreTestmonData(testdir.tmpdir.strpath, variant='1') testmon1_data.node_data['node1'] = {'a.py': 1} testmon1_data.write_data() testmon2_data = CoreTestmonData(testdir.tmpdir.strpath, variant='2') testmon2_data.node_data['node1'] = {'a.py': 2} testmon2_data.write_data() testmon_check_data = CoreTestmonData(testdir.tmpdir.strpath, variant='1') testmon_check_data.read_fs() assert testmon1_data.node_data['node1'] == {'a.py': 1}