diff --git a/.gitignore b/.gitignore index 4f2d317b92..1080ffa0ce 100644 --- a/.gitignore +++ b/.gitignore @@ -44,6 +44,7 @@ conf/locale/ko_KR .noseids nosetests.xml .coverage +.coverage.* coverage.xml cover/ cover_html/ diff --git a/common/test/acceptance/.coveragerc b/common/test/acceptance/.coveragerc new file mode 100644 index 0000000000..917af91813 --- /dev/null +++ b/common/test/acceptance/.coveragerc @@ -0,0 +1,15 @@ +[run] +data_file = reports/bok_choy/.coverage +source = lms, cms, common/djangoapps, common/lib +omit = lms/envs/*, cms/envs/*, common/djangoapps/terrain/*, common/djangoapps/*/migrations/*, */test*, */management/*, */urls*, */wsgi* +parallel = True + +[report] +ignore_errors = True + +[html] +title = Bok Choy Test Coverage Report +directory = reports/bok_choy/cover + +[xml] +output = reports/bok_choy/coverage.xml diff --git a/rakelib/bok_choy.rake b/rakelib/bok_choy.rake index ce7810d9e6..bd64e36173 100644 --- a/rakelib/bok_choy.rake +++ b/rakelib/bok_choy.rake @@ -12,11 +12,16 @@ BOK_CHOY_NUM_PARALLEL = ENV.fetch('NUM_PARALLEL', 1).to_i BOK_CHOY_TEST_TIMEOUT = ENV.fetch("TEST_TIMEOUT", 300).to_f # Ensure that we have a directory to put logs and reports -BOK_CHOY_TEST_DIR = File.join(REPO_ROOT, "common", "test", "acceptance", "tests") +BOK_CHOY_DIR = File.join(REPO_ROOT, "common", "test", "acceptance") +BOK_CHOY_TEST_DIR = File.join(BOK_CHOY_DIR, "tests") BOK_CHOY_LOG_DIR = File.join(REPO_ROOT, "test_root", "log") directory BOK_CHOY_LOG_DIR -BOK_CHOY_XUNIT_REPORT = report_dir_path("bok_choy_xunit.xml") +# Reports +BOK_CHOY_REPORT_DIR = report_dir_path("bok_choy") +BOK_CHOY_XUNIT_REPORT = File.join(BOK_CHOY_REPORT_DIR, "xunit.xml") +BOK_CHOY_COVERAGE_RC = File.join(BOK_CHOY_DIR, ".coveragerc") +directory BOK_CHOY_REPORT_DIR BOK_CHOY_SERVERS = { @@ -31,10 +36,8 @@ BOK_CHOY_CACHE = Dalli::Client.new('localhost:11211') def start_servers() BOK_CHOY_SERVERS.each do | service, info | address = "0.0.0.0:#{info[:port]}" - singleton_process( - django_admin(service, 'bok_choy', 'runserver', address), - logfile=info[:log] - ) + cmd = "coverage run --rcfile=#{BOK_CHOY_COVERAGE_RC} -m manage #{service} --settings bok_choy runserver #{address} --traceback --noreload" + singleton_process(cmd, logfile=info[:log]) end end @@ -166,7 +169,9 @@ namespace :'test:bok_choy' do end desc "Run acceptance tests that use the bok-choy framework but skip setup" - task :fast, [:test_spec] => [:check_services, BOK_CHOY_LOG_DIR] do |t, args| + task :fast, [:test_spec] => [ + :check_services, BOK_CHOY_LOG_DIR, BOK_CHOY_REPORT_DIR, :clean_reports_dir + ] do |t, args| # Ensure the test servers are available puts "Starting test servers...".red @@ -186,6 +191,17 @@ namespace :'test:bok_choy' do end end + desc "Generate coverage reports for bok-choy tests" + task :coverage => BOK_CHOY_REPORT_DIR do | t, args | + puts "Combining coverage reports".red + sh("coverage combine --rcfile=#{BOK_CHOY_COVERAGE_RC}") + + puts "Generating coverage reports".red + sh("coverage html --rcfile=#{BOK_CHOY_COVERAGE_RC}") + sh("coverage xml --rcfile=#{BOK_CHOY_COVERAGE_RC}") + sh("coverage report --rcfile=#{BOK_CHOY_COVERAGE_RC}") + end + end