Skip to content

Commit

Permalink
test: adds timeout and skips some breaking integration tests (#1890)
Browse files Browse the repository at this point in the history
* test: adds pytest-timeout to prevent some failing tests from running forever

* fix(test): skip plugin install integration tests because they reinstall ape

* test: make skip reason string clearer

* test: adds --includepip pytest option to skip tests marked as pip

* test: add `@run_once` decorator to pip marked tests
  • Loading branch information
mikeshultz authored Jan 30, 2024
1 parent 7c5b10b commit 6696e6a
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 7 deletions.
4 changes: 3 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ norecursedirs = "projects"
addopts = "-p no:ape_test" # NOTE: Prevents the ape plugin from activating on our tests
python_files = "test_*.py"
testpaths = "tests"
markers = "fuzzing: Run Hypothesis fuzz test suite"
markers = """fuzzing: Run Hypothesis fuzz test suite
pip: tests that rely on pip install operations"""
timeout = 300

[tool.isort]
line_length = 100
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"pytest-xdist>=3.5.0,<4", # Multi-process runner
"pytest-cov>=4.0.0,<5", # Coverage analyzer plugin
"pytest-mock", # For creating mocks
"pytest-timeout~=2.2.0",
"hypothesis>=6.2.0,<7.0", # Strategy-based fuzzer
"hypothesis-jsonschema==0.19.0", # JSON Schema fuzzer extension
],
Expand Down
11 changes: 11 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,17 @@
explorer_test = pytest.mark.xdist_group(name="explorer-tests")


def pytest_addoption(parser):
parser.addoption(
"--includepip", action="store_true", help="run tests that depend on pip install operations"
)


def pytest_runtest_setup(item):
if "pip" in item.keywords and not item.config.getoption("--includepip"):
pytest.skip("need --includepip option to run this test")


@pytest.fixture(autouse=True)
def setenviron(monkeypatch):
"""
Expand Down
17 changes: 11 additions & 6 deletions tests/integration/cli/test_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import pytest

from tests.integration.cli.utils import github_xfail
from tests.integration.cli.utils import github_xfail, run_once

TEST_PLUGIN_NAME = "tokens"
TEST_PLUGIN_NAME_2 = "optimism"
Expand Down Expand Up @@ -129,25 +129,29 @@ def test_list_does_not_repeat(ape_plugins_runner, installed_plugin):
assert "ethereum" not in result.available_plugins


@github_xfail()
@pytest.mark.pip
@run_once
def test_upgrade(ape_plugins_runner, installed_plugin):
result = ape_plugins_runner.invoke(["install", TEST_PLUGIN_NAME, "--upgrade"])
assert result.exit_code == 0


@github_xfail()
@pytest.mark.pip
@run_once
def test_upgrade_failure(ape_plugins_runner):
result = ape_plugins_runner.invoke(["install", "NOT_EXISTS", "--upgrade"])
assert result.exit_code == 1


@github_xfail()
@pytest.mark.pip
@run_once
def test_install_multiple_in_one_str(ape_plugins_runner):
result = ape_plugins_runner.invoke(["install", f"{TEST_PLUGIN_NAME} {TEST_PLUGIN_NAME_2}"])
assert result.exit_code == 0


@github_xfail()
@pytest.mark.pip
@run_once
def test_install_from_config_file(ape_cli, runner, temp_config):
plugins_config = {"plugins": [{"name": TEST_PLUGIN_NAME}]}
with temp_config(plugins_config):
Expand All @@ -156,7 +160,8 @@ def test_install_from_config_file(ape_cli, runner, temp_config):
assert TEST_PLUGIN_NAME in result.stdout


@github_xfail()
@pytest.mark.pip
@run_once
def test_uninstall(ape_cli, runner, installed_plugin):
result = runner.invoke(
ape_cli, ["plugins", "uninstall", TEST_PLUGIN_NAME, "--yes"], catch_exceptions=False
Expand Down

0 comments on commit 6696e6a

Please sign in to comment.