Class: LearnTest::Strategies::Pytest

Inherits:
LearnTest::Strategy show all
Defined in:
lib/learn_test/strategies/pytest.rb

Instance Attribute Summary

Attributes inherited from LearnTest::Strategy

#options, #runner

Instance Method Summary collapse

Methods inherited from LearnTest::Strategy

#argv, #configure, #die, #initialize, #learn_oauth_token, #push_results?, #run_install, #user_id, #username

Constructor Details

This class inherits a constructor from LearnTest::Strategy

Instance Method Details

#check_dependenciesObject



16
17
18
# File 'lib/learn_test/strategies/pytest.rb', line 16

def check_dependencies
  LearnTest::Pytest::RequirementsChecker.check_installation
end

#cleanupObject



57
58
59
# File 'lib/learn_test/strategies/pytest.rb', line 57

def cleanup
  FileUtils.rm('.results.xml')
end

#detectObject



12
13
14
# File 'lib/learn_test/strategies/pytest.rb', line 12

def detect
  test_files.count > 0
end

#outputObject



24
25
26
# File 'lib/learn_test/strategies/pytest.rb', line 24

def output
  @output ||= Crack::XML.parse(File.read('.results.xml'))["testsuite"]
end

#resultsObject



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/learn_test/strategies/pytest.rb', line 33

def results
  failed_count = output["failures"].to_i + output["errors"].to_i
  skipped_count = output["skips"].to_i
  passed_count = output["tests"].to_i - failed_count - skipped_count
  {
    username: username,
    github_user_id: user_id,
    learn_oauth_token: learn_oauth_token,
    repo_name: runner.repo,
    build: {
      test_suite: [{
        framework: 'pytest',
        formatted_output: output.to_json,
        duration: output["time"]
      }]
    },
    examples: output["tests"].to_i,
    passing_count: passed_count,
    pending_count: skipped_count,
    failure_count: failed_count,
    failure_descriptions: concat_failure_descriptions
  }
end

#runObject



20
21
22
# File 'lib/learn_test/strategies/pytest.rb', line 20

def run
  system("python -m pytest #{options[:argv].join(' ')} --junitxml='./.results.xml'")
end

#service_endpointObject



8
9
10
# File 'lib/learn_test/strategies/pytest.rb', line 8

def service_endpoint
  '/e/flatiron_pytest'
end

#test_filesObject



28
29
30
31
# File 'lib/learn_test/strategies/pytest.rb', line 28

def test_files
  # pytest will run all files of the form test_*.py or *_test.py
  @test_files ||= Dir.glob("**/test_*.py") + Dir.glob("**/*_test.py")
end