Skip to content

Commit

Permalink
Merge pull request #64 from Anaconda-Platform/slow-tests
Browse files Browse the repository at this point in the history
Add --skip-slow-tests option to setup.py and mark slow tests as such
  • Loading branch information
havocp committed May 17, 2017
2 parents 5998681 + 5575678 commit d74b2a1
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 1 deletion.
3 changes: 3 additions & 0 deletions anaconda_project/commands/test/test_prepare.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from __future__ import absolute_import, print_function

import os
import pytest

from anaconda_project.commands.main import _parse_args_and_run_subcommand
from anaconda_project.commands.prepare import prepare_command, main
Expand Down Expand Up @@ -318,6 +319,7 @@ def check_prepare_choose_environment_does_not_exist(dirname):
"""}, check_prepare_choose_environment_does_not_exist)


@pytest.mark.slow
def test_prepare_command_choose_command_chooses_env_spec(capsys):
def check(dirname):
project_dir_disable_dedicated_env(dirname)
Expand Down Expand Up @@ -592,6 +594,7 @@ def mock_console_input(prompt, encrypted):
"""}, check)


@pytest.mark.slow
def test_no_ask_conda_prefix_interactively(monkeypatch, capsys):
def check(dirname):
project_dir_disable_dedicated_env(dirname)
Expand Down
8 changes: 8 additions & 0 deletions anaconda_project/internal/test/test_conda_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ def test_conda_info():
assert 'envs' in json


@pytest.mark.slow
def test_conda_create_and_install_and_remove(monkeypatch):
monkeypatch_conda_not_to_use_links(monkeypatch)

Expand Down Expand Up @@ -115,6 +116,7 @@ def _assert_packages_not_found(e):
raise AssertionError("Expecting package not found error, got: %s" % repr(e))


@pytest.mark.slow
def test_conda_create_bad_package():
def do_test(dirname):
envdir = os.path.join(dirname, "myenv")
Expand All @@ -128,6 +130,7 @@ def do_test(dirname):
with_directory_contents(dict(), do_test)


@pytest.mark.slow
def test_conda_install_no_packages(monkeypatch):
monkeypatch_conda_not_to_use_links(monkeypatch)

Expand All @@ -143,6 +146,7 @@ def do_test(dirname):
with_directory_contents(dict(), do_test)


@pytest.mark.slow
def test_conda_remove_no_packages(monkeypatch):
monkeypatch_conda_not_to_use_links(monkeypatch)

Expand Down Expand Up @@ -612,6 +616,7 @@ def test_environ_set_prefix_to_root():
assert environ['CONDA_DEFAULT_ENV'] == 'root'


@pytest.mark.slow
def test_resolve_dependencies_with_actual_conda_current_platform():
try:
result = conda_api.resolve_dependencies(['bokeh=0.12.4'], platform=None)
Expand All @@ -626,6 +631,7 @@ def test_resolve_dependencies_with_actual_conda_current_platform():
assert len(result) > 1 # bokeh has some dependencies so should be >1


@pytest.mark.slow
def test_resolve_dependencies_with_actual_conda_other_platforms():
for p in conda_api.default_platforms_plus_32_bit:
if p == conda_api.current_platform():
Expand All @@ -647,6 +653,7 @@ def test_resolve_dependencies_with_actual_conda_other_platforms():
print("Dependency resolution test OK on %s" % p)


@pytest.mark.slow
def test_resolve_dependencies_for_bogus_package_with_actual_conda():
with pytest.raises(conda_api.CondaError) as excinfo:
conda_api.resolve_dependencies(['doesnotexistblahblah'])
Expand Down Expand Up @@ -1031,6 +1038,7 @@ def test_current_platform_is_in_default():
assert conda_api.current_platform() in conda_api.default_platforms


@pytest.mark.slow
def test_msys_for_all_platforms():
for p in conda_api.default_platforms_plus_32_bit:
(name, bits) = conda_api.parse_platform(p)
Expand Down
3 changes: 3 additions & 0 deletions anaconda_project/internal/test/test_default_conda_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ def do_test(dirname):
with_directory_contents(dict(), do_test)


@pytest.mark.slow
def test_conda_create_and_install_and_remove(monkeypatch):
monkeypatch_conda_not_to_use_links(monkeypatch)

Expand Down Expand Up @@ -250,6 +251,7 @@ def mock_call_pip(*args, **kwargs):
with_directory_contents(dict(), do_test)


@pytest.mark.slow
def test_timestamp_file_works(monkeypatch):
monkeypatch_conda_not_to_use_links(monkeypatch)

Expand Down Expand Up @@ -418,6 +420,7 @@ def mock_resolve_dependencies(pkgs, platform, channels):
assert lock_set.package_specs_for_current_platform == ('bokeh=0.12.4=0', 'thing=1.0=1')


@pytest.mark.slow
def test_resolve_dependencies_with_actual_conda():
manager = DefaultCondaManager()

Expand Down
2 changes: 2 additions & 0 deletions anaconda_project/internal/test/test_pip_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

# lots is in this one big test so we don't have to create
# tons of environments
@pytest.mark.slow
def test_conda_create_and_install_and_remove_pip_stuff(monkeypatch):
monkeypatch_conda_not_to_use_links(monkeypatch)

Expand Down Expand Up @@ -60,6 +61,7 @@ def do_test(dirname):

# lots is in this one big test so we don't have to create
# tons of environments
@pytest.mark.slow
def test_pip_errors(monkeypatch):
monkeypatch_conda_not_to_use_links(monkeypatch)

Expand Down
3 changes: 3 additions & 0 deletions anaconda_project/plugins/providers/test/test_conda_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import os
import platform
import pytest

import anaconda_project.internal.conda_api as conda_api
import anaconda_project.internal.pip_api as pip_api
Expand Down Expand Up @@ -40,6 +41,7 @@ def test_find_by_class_name_conda_env():
assert isinstance(found, CondaEnvProvider)


@pytest.mark.slow
def test_prepare_and_unprepare_project_scoped_env(monkeypatch):
monkeypatch_conda_not_to_use_links(monkeypatch)

Expand Down Expand Up @@ -173,6 +175,7 @@ def prepare_project_scoped_env_not_attempted(dirname):
with_directory_contents_completing_project_file(dict(), prepare_project_scoped_env_not_attempted)


@pytest.mark.slow
def test_prepare_project_scoped_env_with_packages(monkeypatch):
monkeypatch_conda_not_to_use_links(monkeypatch)

Expand Down
3 changes: 3 additions & 0 deletions anaconda_project/test/test_prepare.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import anaconda_project.internal.keyring as keyring


@pytest.mark.slow
def test_prepare_empty_directory():
def prepare_empty(dirname):
project = Project(dirname)
Expand All @@ -56,6 +57,7 @@ def prepare_bad_provide_mode(dirname):
with_directory_contents(dict(), prepare_bad_provide_mode)


@pytest.mark.slow
@pytest.mark.skipif(platform.system() == 'Windows' and
not (sys.version_info.major == 3 and sys.version_info.minor == 4),
reason="on Windows, can't delete env dir except on python 3.4, don't know why")
Expand Down Expand Up @@ -88,6 +90,7 @@ def unprepare_problems(dirname):
with_directory_contents_completing_project_file({DEFAULT_PROJECT_FILENAME: "variables:\n 42"}, unprepare_problems)


@pytest.mark.slow
def test_unprepare_nothing_to_do():
def unprepare_nothing(dirname):
project = Project(dirname)
Expand Down
1 change: 1 addition & 0 deletions anaconda_project/test/test_project_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -1304,6 +1304,7 @@ def check(dirname):

# the other add_env_spec tests use a mock CondaManager, but we want to have
# one test that does the real thing to be sure it works.
@pytest.mark.slow
def test_add_env_spec_with_real_conda_manager(monkeypatch):
monkeypatch_conda_not_to_use_links(monkeypatch)

Expand Down
11 changes: 10 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from __future__ import print_function

import codecs
import copy
import errno
import os
import platform
Expand Down Expand Up @@ -160,6 +161,7 @@ class AllTestsCommand(TestCommand):
user_options = [('pytest-args=', 'a', "Arguments to pass to py.test"),
('format-only', None, "Only run the linters and formatters not the actual tests"),
('git-staged-only', None, "Only run the linters and formatters on files added to the commit"),
('skip-slow-tests', None, "Skip tests marked slow"),
('profile-formatting', None, "Profile the linter and formatter steps")]

def initialize_options(self):
Expand Down Expand Up @@ -192,6 +194,7 @@ def initialize_options(self):
self.format_only = False
self.git_staged_only = False
self.profile_formatting = False
self.skip_slow_tests = False

def _py_files(self):
if self.pyfiles is None:
Expand Down Expand Up @@ -379,8 +382,14 @@ def ignore_set_level(level):
def _pytest(self):
import pytest
from pytest_cov.plugin import CoverageError

pytest_args = copy.copy(self.pytest_args)
if self.skip_slow_tests:
pytest_args.append("-k-slow")
print("Skipping slow tests")

try:
errno = pytest.main(self.pytest_args)
errno = pytest.main(pytest_args)
if errno != 0:
print("pytest failed, code {errno}".format(errno=errno))
self.failed.append('pytest')
Expand Down

0 comments on commit d74b2a1

Please sign in to comment.