Skip to content

Commit

Permalink
test: speed up test_main
Browse files Browse the repository at this point in the history
  • Loading branch information
akaihola committed Nov 17, 2024
1 parent d987c58 commit ceb678b
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions src/graylint/tests/test_main.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
"""Tests for the `graylint.__main__` module."""

# pylint: disable=no-member,redefined-outer-name

import os
from contextlib import nullcontext
from unittest.mock import Mock, patch

import pytest

from darkgraylib.testtools.git_repo_plugin import GitRepoFixture
from graylint.__main__ import main, main_with_error_handling


Expand All @@ -24,6 +27,15 @@ def test_main_retval(numfails, expect_retval):
assert retval == expect_retval


@pytest.fixture(scope="module")
def main_repo(request, tmp_path_factory):
"""Git repository fixture for `test_main`."""
with GitRepoFixture.context(request, tmp_path_factory) as repo:
paths = repo.add({"subdir/a.py": "\n", "my.cfg": ""}, commit="Initial commit")
paths["subdir/a.py"].write_text("Foo\n")
yield repo


@pytest.mark.kwparametrize(
dict(arguments=["{repo_root}"], expect_retval=0),
dict(
Expand All @@ -42,18 +54,16 @@ def test_main_retval(numfails, expect_retval):
expect_exit=nullcontext(),
)
def test_main(
git_repo,
main_repo,
capsys,
arguments,
expect_retval,
expect_output,
expect_exit,
):
"""Main function return value is 1 if there are linter errors."""
paths = git_repo.add({"subdir/a.py": "\n", "my.cfg": ""}, commit="Initial commit")
paths["subdir/a.py"].write_text("Foo\n")
rendered_arguments = [
argument.format(repo_root=str(git_repo.root)) for argument in arguments
argument.format(repo_root=str(main_repo.root)) for argument in arguments
]
with expect_exit:

Expand Down

0 comments on commit ceb678b

Please sign in to comment.