mercredi 2 décembre 2015

Make a python py.test unit test run independantly of the location where py.test in executed?

Lets say my code looks like this

import pytest
import json

@pytest.fixture
def test_item():
    test_item = json.load(open('./directory/sample_item_for_test.json','rb'))
    return test_item

def test_fun(test_document):
    assert  type(test_item.description[0]) == unicode

And I would like to run this test via Py.Test

If I run Py.test from the directory that it is in, it is fine. BUT if I run it from an above directory, it fails due to not being able to find 'sample_item_for_test.json'. Is there a way to make this test run correctly no matter where I execute Py.test?

Aucun commentaire:

Enregistrer un commentaire