I have a powerful test function that does not work (as it should) with some inputs of the device. How can I indicate this? This is what I am doing right now, and maybe there is a better way. I am new to py.test , so I will be grateful for any advice.
The next part presents all the input lights. FYI, example_datapackage_path is defined in conf.test
@pytest.fixture(params=[None, 'pooled_col', 'phenotype_col']) def metadata_key(self, request): return request.param @pytest.fixture(params=[None, 'feature_rename_col']) def expression_key(self, request): return request.param @pytest.fixture(params=[None, 'feature_rename_col']) def splicing_key(self, request): return request.param @pytest.fixture def datapackage(self, example_datapackage_path, metadata_key, expression_key, splicing_key): with open(example_datapackage_path) as f: datapackage = json.load(f) datatype_to_key = {'metadata': metadata_key, 'expression': expression_key, 'splicing': splicing_key} for datatype, key in datatype_to_key.iteritems(): if key is not None: resource = name_to_resource(datapackage, datatype) if key in resource: resource.pop(key) return datapackage @pytest.fixture def datapackage_dir(self, example_datapackage_path): return os.path.dirname(example_datapackage_path)
And here is the test itself.
def test_from_datapackage(self, datapackage, datapackage_dir): import flotilla from flotilla.external import get_resource_from_name study = flotilla.Study.from_datapackage(datapackage, datapackage_dir, load_species_data=False) metadata_resource = get_resource_from_name(datapackage, 'metadata') expression_resource = get_resource_from_name(datapackage, 'expression') splicing_resource = get_resource_from_name(datapackage, 'splicing') phenotype_col = 'phenotype' if 'phenotype_col' \ not in metadata_resource else metadata_resource['phenotype_col'] pooled_col = None if 'pooled_col' not in metadata_resource else \ metadata_resource['pooled_col'] expression_feature_rename_col = 'gene_name' if \ 'feature_rename_col' not in expression_resource \ else expression_resource['feature_rename_col'] splicing_feature_rename_col = 'gene_name' if \ 'feature_rename_col' not in splicing_resource \ else splicing_resource['feature_rename_col'] assert study.metadata.phenotype_col == phenotype_col assert study.metadata.pooled_col == pooled_col assert study.expression.feature_rename_col \ == expression_feature_rename_col assert study.splicing.feature_rename_col == splicing_feature_rename_col
What I would like to do is in metadata_key , let's say that when the pooled_col or phenotype_col parameter, it will fail. I looked in pytest: Skip and xfail: to cope with tests that cannot be successful , but he only talked about skip and xfail for a parameterized test, but not for instruments.