瀏覽代碼

Add slow marker for python tests

Allows to use `pytest --quick` and `pytest --slow` to skip / only run tests marked as slow.
Vidar Tonaas Fauske 5 年之前
父節點
當前提交
8fb3f7f6ab
共有 3 個文件被更改,包括 43 次插入0 次删除
  1. 35 0
      conftest.py
  2. 3 0
      jupyterlab/tests/test_build_api.py
  3. 5 0
      jupyterlab/tests/test_jupyterlab.py

+ 35 - 0
conftest.py

@@ -0,0 +1,35 @@
+# -*- coding: utf-8 -*-
+
+# Copyright (c) Jupyter Development Team.
+# Distributed under the terms of the Modified BSD License.
+
+import pytest
+
+def pytest_addoption(parser):
+    """
+    Adds flags for py.test.
+
+    This is called by the pytest API
+    """
+    group = parser.getgroup("general")
+    group.addoption('--quick', action='store_true',
+                    help="Skip slow tests")
+    group.addoption('--slow', action='store_true',
+                    help="Run only slow tests")
+
+
+def pytest_configure(config):
+    config.addinivalue_line("markers", "slow: mark test as slow to run")
+
+
+def pytest_collection_modifyitems(config, items):
+    if config.getoption("--quick"):
+        skip_slow = pytest.mark.skip(reason="skipping slow test")
+        for item in items:
+            if "slow" in item.keywords:
+                item.add_marker(skip_slow)
+    elif config.getoption("--slow"):
+        skip_quick = pytest.mark.skip(reason="skipping non-slow test")
+        for item in items:
+            if "slow" not in item.keywords:
+                item.add_marker(skip_quick)

+ 3 - 0
jupyterlab/tests/test_build_api.py

@@ -2,6 +2,8 @@
 from tempfile import TemporaryDirectory
 import threading
 
+import pytest
+
 from jupyterlab.labapp import LabApp
 from jupyterlab_server.tests.utils import APITester, LabTestBase
 from notebook.tests.launchnotebook import assert_http_error
@@ -21,6 +23,7 @@ class BuildAPITester(APITester):
         return self._req('DELETE', '')
 
 
+@pytest.mark.slow
 class BuildAPITest(LabTestBase):
     """Test the build web service API"""
     Application = LabApp

+ 5 - 0
jupyterlab/tests/test_jupyterlab.py

@@ -217,6 +217,7 @@ class TestExtension(TestCase):
         assert mime_ext_name not in extensions
 
 
+    @pytest.mark.slow
     def test_uninstall_core_extension(self):
         assert uninstall_extension('@jupyterlab/console-extension') is True
         app_dir = self.app_dir
@@ -407,6 +408,7 @@ class TestExtension(TestCase):
         assert ext_name not in extensions
         assert not check_extension(ext_name, app_dir)
 
+    @pytest.mark.slow
     def test_build(self):
         assert install_extension(self.mock_extension) is True
         build()
@@ -422,6 +424,7 @@ class TestExtension(TestCase):
             data = fid.read()
         assert self.pkg_names['extension'] in data
 
+    @pytest.mark.slow
     def test_build_custom(self):
         assert install_extension(self.mock_extension) is True
         build(name='foo', version='1.0', static_url='bar')
@@ -439,6 +442,7 @@ class TestExtension(TestCase):
         assert data['jupyterlab']['version'] == '1.0'
         assert data['jupyterlab']['staticUrl'] == 'bar'
 
+    @pytest.mark.slow
     def test_build_custom_minimal_core_config(self):
         default_config = CoreConfig()
         core_config = CoreConfig()
@@ -525,6 +529,7 @@ class TestExtension(TestCase):
         assert '@jupyterlab/notebook-extension' not in info['disabled']
         assert not check_extension('@jupyterlab/notebook-extension', app_dir)
 
+    @pytest.mark.slow
     def test_build_check(self):
         # Do the initial build.
         assert build_check()