Bug 1417920 - [python-test] Use a global pytest.ini configuration file, r?davehunt draft
authorAndrew Halberstadt <ahalberstadt@mozilla.com>
Wed, 06 Jun 2018 14:00:04 -0400
changeset 805303 14eb0d35a5811bbc8f0da3641048211b4c519e41
parent 805204 199a085199815cc99daa658956a7c9436e1d436b
push id112626
push userahalberstadt@mozilla.com
push dateThu, 07 Jun 2018 16:35:07 +0000
reviewersdavehunt
bugs1417920
milestone62.0a1
Bug 1417920 - [python-test] Use a global pytest.ini configuration file, r?davehunt This changes two config options: pytest_classes = PyTest # only classes that start with 'PyTest' will be considered tests (previously this was Test) xfail_strict = true # tests marked as xfail will cause pytest to return non-zero if they unexpectedly pass MozReview-Commit-ID: DCWoDFbe6Mk
config/mozunit/mozunit/mozunit.py
config/mozunit/mozunit/pytest.ini
testing/marionette/harness/marionette_harness/tests/harness_unit/pytest.ini
testing/marionette/harness/marionette_harness/tests/harness_unit/test_httpd.py
testing/marionette/harness/marionette_harness/tests/harness_unit/test_marionette_arguments.py
testing/marionette/harness/marionette_harness/tests/harness_unit/test_marionette_harness.py
testing/marionette/harness/marionette_harness/tests/harness_unit/test_marionette_runner.py
testing/marionette/harness/marionette_harness/tests/harness_unit/test_marionette_test_result.py
testing/marionette/harness/marionette_harness/tests/harness_unit/test_serve.py
tools/lint/test/test_flake8.py
--- a/config/mozunit/mozunit/mozunit.py
+++ b/config/mozunit/mozunit/mozunit.py
@@ -7,16 +7,18 @@ import inspect
 import os
 import sys
 import unittest
 from unittest import TextTestRunner as _TestRunner, TestResult as _TestResult
 
 import pytest
 import six
 
+here = os.path.abspath(os.path.dirname(__file__))
+
 StringIO = six.StringIO
 
 '''Helper to make python unit tests report the way that the Mozilla
 unit test infrastructure expects tests to report.
 
 Usage:
 
 import mozunit
@@ -227,14 +229,15 @@ def main(*args, **kwargs):
         unittest.main(testRunner=MozTestRunner(), *args, **kwargs)
     else:
         args = list(args)
         if os.environ.get('MACH_STDOUT_ISATTY') and not any(a.startswith('--color') for a in args):
             args.append('--color=yes')
 
         module = __import__('__main__')
         args.extend([
+            '-c', os.path.join(here, 'pytest.ini'),
             '-vv',
             '-p', 'mozlog.pytest_mozlog.plugin',
             '-p', 'no:cacheprovider',
             module.__file__,
         ])
         sys.exit(pytest.main(args))
new file mode 100644
--- /dev/null
+++ b/config/mozunit/mozunit/pytest.ini
@@ -0,0 +1,3 @@
+[pytest]
+python_classes=PyTest
+xfail_strict=true
deleted file mode 100644
--- a/testing/marionette/harness/marionette_harness/tests/harness_unit/pytest.ini
+++ /dev/null
@@ -1,2 +0,0 @@
-[pytest]
-addopts = -p no:terminalreporter
--- a/testing/marionette/harness/marionette_harness/tests/harness_unit/test_httpd.py
+++ b/testing/marionette/harness/marionette_harness/tests/harness_unit/test_httpd.py
@@ -84,9 +84,9 @@ def test_handler(server):
 
     url = server.get_url("/httpd/test_handler")
     body = urllib2.urlopen(url).read()
     res = json.loads(body)
     assert res["count"] == counter
 
 
 if __name__ == "__main__":
-    mozunit.main('--log-tbpl=-')
+    mozunit.main('-p', 'no:terminalreporter', '--log-tbpl=-')
--- a/testing/marionette/harness/marionette_harness/tests/harness_unit/test_marionette_arguments.py
+++ b/testing/marionette/harness/marionette_harness/tests/harness_unit/test_marionette_arguments.py
@@ -61,9 +61,9 @@ def test_parse_opt_args_emulator(mach_pa
     mach_parsed_kwargs[arg_dest] = result[arg_dest]
     mach_parsed_kwargs["emulator"] = True
     runner = MarionetteTestRunner(**mach_parsed_kwargs)
     built_kwargs = runner._build_kwargs()
     assert built_kwargs[arg_dest] == expected_value
 
 
 if __name__ == '__main__':
-    mozunit.main('--log-tbpl=-')
+    mozunit.main('-p', 'no:terminalreporter', '--log-tbpl=-')
--- a/testing/marionette/harness/marionette_harness/tests/harness_unit/test_marionette_harness.py
+++ b/testing/marionette/harness/marionette_harness/tests/harness_unit/test_marionette_harness.py
@@ -102,9 +102,9 @@ def test_harness_sets_up_default_test_ha
     """
     harness = MarionetteHarness(args=mach_parsed_kwargs)
     mach_parsed_kwargs.pop('tests')
     runner = harness._runner_class(**mach_parsed_kwargs)
     assert marionette_test.MarionetteTestCase in runner.test_handlers
 
 
 if __name__ == '__main__':
-    mozunit.main('--log-tbpl=-')
+    mozunit.main('-p', 'no:terminalreporter', '--log-tbpl=-')
--- a/testing/marionette/harness/marionette_harness/tests/harness_unit/test_marionette_runner.py
+++ b/testing/marionette/harness/marionette_harness/tests/harness_unit/test_marionette_runner.py
@@ -502,9 +502,9 @@ def test_option_run_until_failure(mach_p
         assert runner.run_until_failure == run_until_failure
         if repeat is None:
             assert runner.repeat == 30
         else:
             assert runner.repeat == repeat
 
 
 if __name__ == '__main__':
-    mozunit.main('--log-tbpl=-')
+    mozunit.main('-p', 'no:terminalreporter', '--log-tbpl=-')
--- a/testing/marionette/harness/marionette_harness/tests/harness_unit/test_marionette_test_result.py
+++ b/testing/marionette/harness/marionette_harness/tests/harness_unit/test_marionette_test_result.py
@@ -48,9 +48,9 @@ def test_crash_is_recorded_as_error(empt
     assert result.shouldStop == has_crashed
     if has_crashed:
         assert len(result.errors) == 1
     else:
         assert len(result.errors) == 0
 
 
 if __name__ == '__main__':
-    mozunit.main('--log-tbpl=-')
+    mozunit.main('-p', 'no:terminalreporter', '--log-tbpl=-')
--- a/testing/marionette/harness/marionette_harness/tests/harness_unit/test_serve.py
+++ b/testing/marionette/harness/marionette_harness/tests/harness_unit/test_serve.py
@@ -61,9 +61,9 @@ def test_iter_url():
 
 def test_where_is():
     serve.start()
     assert serve.where_is("/") == serve.servers["http"][1].get_url("/")
     assert serve.where_is("/", on="https") == serve.servers["https"][1].get_url("/")
 
 
 if __name__ == "__main__":
-    mozunit.main('--log-tbpl=-')
+    mozunit.main('-p', 'no:terminalreporter', '--log-tbpl=-')
--- a/tools/lint/test/test_flake8.py
+++ b/tools/lint/test/test_flake8.py
@@ -62,24 +62,23 @@ foo = ['A list of strings', 'that go ove
     lint([path], fix=True)
 
     # Make sure autopep8 reads the global config under lintargs['root']. If it
     # didn't, then the line-length over 80 would get fixed.
     with open(path, 'r') as fh:
         assert fh.read() == contents
 
 
-@pytest.mark.xfail(
-    strict=True, reason="Bug 1277851 - custom configs are ignored if specifying a parent path")
+@pytest.mark.xfail(reason="Bug 1277851 - custom configs are ignored if specifying a parent path")
 def test_lint_custom_config_from_parent_path(lint, paths):
     results = lint(paths(), collapse_results=True)
     assert paths('custom/good.py')[0] not in results
 
 
-@pytest.mark.xfail(strict=True, reason="Bug 1277851 - 'exclude' argument is ignored")
+@pytest.mark.xfail(reason="Bug 1277851 - 'exclude' argument is ignored")
 def test_lint_excluded_file(lint, paths):
     paths = paths('bad.py')
     results = lint(paths, exclude=paths)
     assert len(results) == 0
 
 
 if __name__ == '__main__':
     mozunit.main()