Skip to content

Commit

Permalink
Proper fix for double colon issue
Browse files Browse the repository at this point in the history
  • Loading branch information
mbachry authored and Marcin Bachry committed Jun 10, 2019
1 parent 381cd0e commit 4e977a3
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 40 deletions.
9 changes: 1 addition & 8 deletions pytest_sugar.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,17 +368,10 @@ def begin_new_line(self, report, print_filename):
basename = os.path.basename(fspath)
if print_filename:
if self.showlongtestinfo:
test_location = report.location[0]
test_name = report.location[2]
test_location, _, test_name = report.nodeid.partition('::')
else:
test_location = fspath[0:-len(basename)]
test_name = fspath[-len(basename):]
if test_location:
pass
# only replace if test_location is not empty, if it is,
# test_name contains the filename
# FIXME: This doesn't work.
# test_name = test_name.replace('.', '::')
self.current_lines[path] = (
" " +
colored(test_location, THEME['path']) +
Expand Down
69 changes: 37 additions & 32 deletions test_sugar.py
Original file line number Diff line number Diff line change
Expand Up @@ -473,38 +473,43 @@ def test_true():
output
)

# def test_verbose_has_double_colon_with_class(self, testdir):
# testdir.makepyfile(
# """
# class TestTrue:

# def test_true(self):
# assert True
# """
# )
# output = testdir.runpytest(
# '--force-sugar', '--verbose'
# ).stdout.str()

# test_name = (
# 'test_verbose_has_double_colon_with_class.py::TestTrue::test_true')
# assert test_name in strip_colors(output)

# def test_not_verbose_no_double_colon_filename(self, testdir):
# testdir.makepyfile(
# """
# class TestTrue:

# def test_true(self):
# assert True
# """
# )
# output = testdir.runpytest(
# '--force-sugar'
# ).stdout.str()

# test_name = 'test_not_verbose_no_double_colon_filename.py'
# assert test_name in strip_colors(output)
def test_verbose_has_double_colon_with_class(self, testdir):
testdir.makepyfile(
"""
class TestTrue:
def test_true(self):
assert True
"""
)
output = testdir.runpytest(
'--force-sugar', '--verbose'
).stdout.str()

# see: https://github.com/pytest-dev/pytest/commit/ac8b9c6e9dbb66114a1c3f79cd1fdeb0b2b2c54d
if LooseVersion(pytest.__version__) < LooseVersion('4.0'):
test_name = (
'test_verbose_has_double_colon_with_class.py::TestTrue::()::test_true')
else:
test_name = (
'test_verbose_has_double_colon_with_class.py::TestTrue::test_true')
assert test_name in strip_colors(output)

def test_not_verbose_no_double_colon_filename(self, testdir):
testdir.makepyfile(
"""
class TestTrue:
def test_true(self):
assert True
"""
)
output = testdir.runpytest(
'--force-sugar'
).stdout.str()

test_name = 'test_not_verbose_no_double_colon_filename.py'
assert test_name in strip_colors(output)

def test_xdist(self, testdir):
pytest.importorskip("xdist")
Expand Down

0 comments on commit 4e977a3

Please sign in to comment.