Skip to content

Commit

Permalink
Ignore spaces in assert message tests (#11478)
Browse files Browse the repository at this point in the history
* Update assert message formatting

* Add space

* Add space to assert

* Only one space

* Remove a space

* Revert to before

* see

* fix

Co-authored-by: Ofek Lev <ofekmeister@gmail.com>
  • Loading branch information
sarah-witt and ofek authored Feb 9, 2022
1 parent 690db87 commit f33bb5a
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions datadog_checks_base/tests/stubs/test_aggregator_no_duplicate.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# (C) Datadog, Inc. 2018-present
# All rights reserved
# Licensed under a 3-clause BSD style license (see LICENSE)
from textwrap import dedent

import pytest

from datadog_checks.base import AgentCheck
Expand All @@ -15,24 +17,23 @@ def test_assert_no_duplicate_message(aggregator):
check.gauge('check.metric.no_dup1', 5, tags=['aa'])
check.gauge('check.metric.no_dup2', 6, tags=['aa'])

actual_msg = ""
actual_msg = " "
try:
aggregator.assert_no_duplicate_metrics()
except AssertionError as e:
actual_msg = str(e)
actual_msg += str(e).split("assert")[0].lstrip()
actual_msg = dedent(actual_msg)

expected_msg = '''
Duplicate metrics found:
- check.metric.dup1
MetricStub(name='check.metric.dup1', type=0, value=1.0, tags=['aa'], hostname='', device=None, flush_first_value=False)
MetricStub(name='check.metric.dup1', type=0, value=2.0, tags=['aa'], hostname='', device=None, flush_first_value=False)
- check.metric.dup2
MetricStub(name='check.metric.dup2', type=0, value=3.0, tags=['aa'], hostname='', device=None, flush_first_value=False)
MetricStub(name='check.metric.dup2', type=0, value=4.0, tags=['aa'], hostname='', device=None, flush_first_value=False)
- check.metric.dup1
MetricStub(name='check.metric.dup1', type=0, value=1.0, tags=['aa'], hostname='', device=None, flush_first_value=False)
MetricStub(name='check.metric.dup1', type=0, value=2.0, tags=['aa'], hostname='', device=None, flush_first_value=False)
- check.metric.dup2
MetricStub(name='check.metric.dup2', type=0, value=3.0, tags=['aa'], hostname='', device=None, flush_first_value=False)
MetricStub(name='check.metric.dup2', type=0, value=4.0, tags=['aa'], hostname='', device=None, flush_first_value=False)
''' # noqa: E501
print("\n===\n{}\n===\n".format(expected_msg.strip()))
print("\n===\n{}\n===\n".format(actual_msg.strip()))
assert expected_msg.strip() == actual_msg.split("assert")[0].strip()
assert expected_msg.strip() == actual_msg.strip()


@pytest.mark.parametrize(
Expand Down

0 comments on commit f33bb5a

Please sign in to comment.