Module: Datadog::CI::Contrib::Minitest::Test::InstanceMethods

Defined in:
lib/datadog/ci/contrib/minitest/test.rb

Instance Method Summary collapse

Instance Method Details

#after_teardownObject



61
62
63
64
65
66
67
68
69
70
71
# File 'lib/datadog/ci/contrib/minitest/test.rb', line 61

def after_teardown
  test_span = test_visibility_component.active_test
  return super unless test_span

  finish_with_result(test_span, result_code)

  # remove failures if test passed at least once on retries or quarantined
  self.failures = [] if test_span.should_ignore_failures?

  super
end

#before_setupObject



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/datadog/ci/contrib/minitest/test.rb', line 22

def before_setup
  super
  return unless datadog_configuration[:enabled]

  if Helpers.parallel?(self.class)
    Helpers.start_test_suite(self.class)
  end

  test_suite_name = Helpers.test_suite_name(self.class, name)

  # @type var tags : Hash[String, String]
  tags = {
    CI::Ext::Test::TAG_FRAMEWORK => Ext::FRAMEWORK,
    CI::Ext::Test::TAG_FRAMEWORK_VERSION => datadog_integration.version.to_s
  }

  # try to find out where test method starts and ends
  test_method = method(name)
  source_file, first_line_number = test_method.source_location
  last_line_number = Utils::SourceCode.last_line(test_method)

  tags[CI::Ext::Test::TAG_SOURCE_FILE] = Git::LocalRepository.relative_to_root(source_file) if source_file
  tags[CI::Ext::Test::TAG_SOURCE_START] = first_line_number.to_s if first_line_number
  tags[CI::Ext::Test::TAG_SOURCE_END] = last_line_number.to_s if last_line_number

  test_span = test_visibility_component.trace_test(
    name,
    test_suite_name,
    tags: tags,
    service: datadog_configuration[:service_name]
  )
  # Steep type checker doesn't know that we patched Minitest::Test class definition
  #
  # steep:ignore:start
  test_span&.itr_unskippable! if self.class.dd_suite_unskippable? || self.class.dd_test_unskippable?(name)
  # steep:ignore:end
  skip(test_span&.datadog_skip_reason) if test_span&.should_skip?
end