Commit 90e33867 by Ned Batchelder Committed by Calen Pennington

WIP for quieter tests with coverage.

parent 7eb196df
# .coveragerc for cms
[report]
ignore_errors = True
[html]
directory = reports/cms/cover
[xml]
output = reports/cms/coverage.xml
...@@ -14,6 +14,7 @@ from path import path ...@@ -14,6 +14,7 @@ from path import path
# Nose Test Runner # Nose Test Runner
INSTALLED_APPS += ('django_nose',) INSTALLED_APPS += ('django_nose',)
NOSE_ARGS = ['--with-xunit']
TEST_RUNNER = 'django_nose.NoseTestSuiteRunner' TEST_RUNNER = 'django_nose.NoseTestSuiteRunner'
TEST_ROOT = path('test_root') TEST_ROOT = path('test_root')
......
# .coveragerc for common/lib/capa
[report]
ignore_errors = True
[html]
directory = reports/common/lib/capa/cover
[xml]
output = reports/common/lib/capa/coverage.xml
# .coveragerc for common/lib/xmodule
[report]
ignore_errors = True
[html]
directory = reports/common/xmodule/capa/cover
[xml]
output = reports/common/lib/xmodule/coverage.xml
# .coveragerc for cms
[report]
ignore_errors = True
[html]
directory = reports/lms/cover
[xml]
output = reports/lms/coverage.xml
...@@ -27,7 +27,6 @@ SOUTH_TESTS_MIGRATE = False # To disable migrations and use syncdb instead ...@@ -27,7 +27,6 @@ SOUTH_TESTS_MIGRATE = False # To disable migrations and use syncdb instead
# Nose Test Runner # Nose Test Runner
INSTALLED_APPS += ('django_nose',) INSTALLED_APPS += ('django_nose',)
NOSE_ARGS = []
NOSE_ARGS = [ NOSE_ARGS = [
'--with-xunit', '--with-xunit',
......
...@@ -84,26 +84,33 @@ end ...@@ -84,26 +84,33 @@ end
$failed_tests = 0 $failed_tests = 0
def run_under_coverage(cmd) def run_under_coverage(cmd, root)
cmd0, cmd_rest = cmd.split(" ", 2) cmd0, cmd_rest = cmd.split(" ", 2)
cmd = "coverage run `which #{cmd0}` #{cmd_rest}" # We use "python -m coverage" so that the proper python will run the importable coverage
# rather than the coverage that OS path finds.
cmd = "python -m coverage run --rcfile=#{root}/.coveragerc `which #{cmd0}` #{cmd_rest}"
return cmd return cmd
end end
def coverage_reports(root)
sh("coverage xml --rcfile=#{root}/.coveragerc")
sh("coverage html --rcfile=#{root}/.coveragerc")
end
def run_tests(system, report_dir, stop_on_failure=true) def run_tests(system, report_dir, stop_on_failure=true)
ENV['NOSE_XUNIT_FILE'] = File.join(report_dir, "nosetests.xml") ENV['NOSE_XUNIT_FILE'] = File.join(report_dir, "nosetests.xml")
ENV['NOSE_COVER_HTML_DIR'] = File.join(report_dir, "cover")
dirs = Dir["common/djangoapps/*"] + Dir["#{system}/djangoapps/*"] dirs = Dir["common/djangoapps/*"] + Dir["#{system}/djangoapps/*"]
cmd = django_admin(system, :test, 'test', '--logging-clear-handlers', *dirs.each) cmd = django_admin(system, :test, 'test', '--logging-clear-handlers', *dirs.each)
sh(run_under_coverage(cmd)) do |ok, res| sh(run_under_coverage(cmd, system)) do |ok, res|
if !ok and stop_on_failure if !ok and stop_on_failure
abort "Test failed!" abort "Test failed!"
end end
$failed_tests += 1 unless ok $failed_tests += 1 unless ok
end end
coverage_reports(system)
end end
TEST_TASKS = [] TEST_TASK_SYMBOLS = []
[:lms, :cms].each do |system| [:lms, :cms].each do |system|
report_dir = File.join(REPORT_DIR, system.to_s) report_dir = File.join(REPORT_DIR, system.to_s)
...@@ -120,7 +127,7 @@ TEST_TASKS = [] ...@@ -120,7 +127,7 @@ TEST_TASKS = []
run_tests(system, report_dir, args.stop_on_failure) run_tests(system, report_dir, args.stop_on_failure)
end end
TEST_TASKS << "test_#{system}" TEST_TASK_SYMBOLS << system
desc <<-desc desc <<-desc
Start the #{system} locally with the specified environment (defaults to dev). Start the #{system} locally with the specified environment (defaults to dev).
...@@ -150,7 +157,7 @@ TEST_TASKS = [] ...@@ -150,7 +157,7 @@ TEST_TASKS = []
end end
end end
Dir["common/lib/*"].each do |lib| Dir["common/lib/*"].select{|lib| File.directory?(lib)}.each do |lib|
task_name = "test_#{lib}" task_name = "test_#{lib}"
report_dir = File.join(REPORT_DIR, task_name.gsub('/', '_')) report_dir = File.join(REPORT_DIR, task_name.gsub('/', '_'))
...@@ -160,21 +167,23 @@ Dir["common/lib/*"].each do |lib| ...@@ -160,21 +167,23 @@ Dir["common/lib/*"].each do |lib|
task task_name => report_dir do task task_name => report_dir do
ENV['NOSE_XUNIT_FILE'] = File.join(report_dir, "nosetests.xml") ENV['NOSE_XUNIT_FILE'] = File.join(report_dir, "nosetests.xml")
cmd = "nosetests #{lib} --logging-clear-handlers --with-xunit" cmd = "nosetests #{lib} --logging-clear-handlers --with-xunit"
sh(run_under_coverage(cmd)) sh(run_under_coverage(cmd, lib)) do |ok, res|
$failed_tests += 1 unless ok
end
coverage_reports(lib)
end end
TEST_TASKS << task_name TEST_TASK_SYMBOLS << lib
desc "Run tests for common lib #{lib} (without coverage)" desc "Run tests for common lib #{lib} (without coverage)"
task "fasttest_#{lib}" do task "fasttest_#{lib}" do
sh("nosetests #{lib}") sh("nosetests #{lib}")
end end
end end
task :test do task :test do
TEST_TASKS.each do |task| TEST_TASK_SYMBOLS.each do |sym|
Rake::Task[task].invoke(false) Rake::Task["test_#{sym}"].invoke(false)
end end
if $failed_tests > 0 if $failed_tests > 0
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment