diff --git a/pytest_bdd/cucumber_json.py b/pytest_bdd/cucumber_json.py index 193bdefb..a7c2c770 100644 --- a/pytest_bdd/cucumber_json.py +++ b/pytest_bdd/cucumber_json.py @@ -171,6 +171,8 @@ def pytest_sessionstart(self): self.suite_start_time = time.time() def pytest_sessionfinish(self): + if not os.path.exists(os.path.dirname(self.logfile)): + os.makedirs(os.path.dirname(self.logfile)) if sys.version_info[0] < 3: logfile_open = codecs.open else: diff --git a/tests/feature/test_cucumber_json.py b/tests/feature/test_cucumber_json.py index de41e50b..ec20d089 100644 --- a/tests/feature/test_cucumber_json.py +++ b/tests/feature/test_cucumber_json.py @@ -2,11 +2,22 @@ import json import os.path import textwrap +import pytest + + +@pytest.fixture(params=[None, "a"]) +def testdir(request, testdir): + if request.param: + testdir.missing_subdirectory = testdir.tmpdir.join(request.param) + return testdir def runandparse(testdir, *args): """Run tests in testdir and parse json output.""" - resultpath = testdir.tmpdir.join("cucumber.json") + if hasattr(testdir, "missing_subdirectory"): + resultpath = testdir.missing_subdirectory.join("cucumber.json") + else: + resultpath = testdir.tmpdir.join("cucumber.json") result = testdir.runpytest("--cucumberjson={0}".format(resultpath), "-s", *args) jsonobject = json.load(resultpath.open()) return result, jsonobject @@ -224,7 +235,7 @@ def test_passing_outline(): "name": "Passing outline", }, ], - "id": os.path.join("test_step_trace0", "test.feature"), + "id": os.path.join(testdir.tmpdir.basename, "test.feature"), "keyword": "Feature", "line": 2, "name": "One passing scenario, one failing scenario",