Skip to content
Open
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
25 changes: 24 additions & 1 deletion test/plugins/test_case_time_log_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,15 @@
import mock
from optparse import OptionParser
import time
import os
import subprocess
import sys
import tempfile

import six

from testify import compat
from testify import assert_equal, TestCase
from testify import assert_equal, assert_in, TestCase
from testify.test_result import TestResult
from testify.plugins.test_case_time_log import add_command_line_options, TestCaseJSONReporter

Expand Down Expand Up @@ -73,3 +77,22 @@ def test_json_reporter_reports(self):
json.loads(self.reporter.log_file.getvalue()),
json.loads(output_str),
)

def test_test_case_results_reports(self):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd delete the unit test since this entirely covers the behaviour without fragile mocking

tempdir = tempfile.mkdtemp()
temp_json_file = os.path.join(tempdir, 'tmp.json')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this leaks the tempdir and tempfile, you should use a context manager to clean that up

You can peek at test.discovery_failure_test.BrokenImportTestCase for an example

subprocess.check_call((
sys.executable,
'-m',
'testify.test_program',
'--test-case-results',
temp_json_file,
'test/test_suite_subdir/define_testcase.py'
))
with open(temp_json_file, 'r') as f:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'r' is the default

result = f.readlines()[0]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd just do f.read()

contents = json.loads(result)
assert_in('start_time', contents)
assert_in('end_time', contents)
assert_in('success', contents)
assert_in('method', contents)