Fix running coverage for nose tests (PY-14869)
authorDmitry Trofimov <dmitry.trofimov@jetbrains.com>
Thu, 6 Oct 2016 14:45:51 +0000 (17:45 +0300)
committerDmitry Trofimov <dmitry.trofimov@jetbrains.com>
Thu, 6 Oct 2016 14:45:51 +0000 (17:45 +0300)
python/helpers/coverage_runner/run_coverage.py

index f637d6e8d42c70c4bc12e4b185dd807304aaeecc..1c1f69a881c46c392af0fede8577088dd4e4b72a 100644 (file)
@@ -13,18 +13,22 @@ else:
     from coverage.cmdline import main
 
 coverage_file = os.getenv('PYCHARM_COVERAGE_FILE')
+
+coverage_file = coverage_file[0:-len(".coverage")]
+
 run_cov = os.getenv('PYCHARM_RUN_COVERAGE')
 if os.getenv('CREATE_TEMP_COVERAGE_FILE'):
     line = 'LOG: PyCharm: File mapping:%s\t%s\n'
     import tempfile
     (h, new_cov_file) = tempfile.mkstemp(prefix='pycharm-coverage')
-    print(line%(coverage_file, new_cov_file))
+    print(line%(coverage_file + ".coverage", new_cov_file + ".coverage"))
     print(line%(coverage_file + '.syspath.txt', new_cov_file + '.syspath.txt'))
     print(line%(coverage_file + '.xml', new_cov_file + '.xml'))
-    coverage_file = new_cov_file
+    coverage_file = new_cov_file + ".cov"
 
 if coverage_file:
-    os.environ['COVERAGE_FILE'] = coverage_file
+    os.environ['COVERAGE_FILE'] = coverage_file + ".coverage"
+
 if run_cov:
     a_file = open(coverage_file + '.syspath.txt', mode='w')
     a_file.write(os.getcwd()+"\n")
@@ -41,7 +45,10 @@ for arg in sys.argv:
 sys.argv = argv
 
 cwd = os.getcwd()
-main()
-if run_cov:
-    os.chdir(cwd)
-    main(["xml", "-o", coverage_file + ".xml", "--ignore-errors"])
\ No newline at end of file
+
+try:
+    main()
+finally:
+    if run_cov:
+        os.chdir(cwd)
+        main(["xml", "-o", coverage_file + ".xml", "--ignore-errors"])
\ No newline at end of file