Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Creates path to json file if it does not exist #347

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions pytest_bdd/cucumber_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
15 changes: 13 additions & 2 deletions tests/feature/test_cucumber_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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",
Expand Down