diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f1cbbcf..54a2e4b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -17,18 +17,8 @@ jobs: with: python-version: "3.12" - - name: Set up requirements for simple test - if: github.event_name == 'pull_request' - run: pip install -e ".[test_simple]" - - - name: Test without rpc using test - if: github.event_name == 'pull_request' - run: pytest -l --skip-rpc-using-test --skip-image-test --ignore=tests/additional/test_file.py - - name: Set up requirements - if: github.event_name == 'push' run: pip install -e ".[test]" - name: Test with rpc using test - if: github.event_name == 'push' run: pytest -l diff --git a/requirements/test.txt b/requirements/test.txt index 1c250e9..5933515 100644 --- a/requirements/test.txt +++ b/requirements/test.txt @@ -1,4 +1,5 @@ # Specifies the packages for testing the project. +GitPython==3.1.43 pytest==7.4.4 pytest-asyncio==0.23.7 pigar==2.1.6 diff --git a/tests/additional/test_rpc.py b/tests/additional/test_rpc.py index c18c7a3..585ce45 100644 --- a/tests/additional/test_rpc.py +++ b/tests/additional/test_rpc.py @@ -2,9 +2,9 @@ from copy import deepcopy from pathlib import Path from re import search -from subprocess import run, PIPE import pytest +from git import Repo from pydantic import HttpUrl from web3 import Web3, HTTPProvider @@ -71,11 +71,18 @@ async def __test_rpc_url(self, network: Network): pass @pytest.mark.asyncio - async def test_all_contracts_info_valid(self): + async def test_modified_contracts_info_valid(self): """All contracts in asset information are valid.""" for asset in self.__filter_modified_assets(): await gather(*[self.__test_all_contract_info_valid(asset)]) + @pytest.mark.all + @pytest.mark.asyncio + async def test_all_contracts_info_valid(self): + """All contracts in asset information are valid.""" + for asset, _ in self.asset_list: + await gather(*[self.__test_all_contract_info_valid(asset)]) + async def __test_all_contract_info_valid(self, asset: Asset): """Test the validity of the contract information. @@ -107,26 +114,10 @@ async def __test_all_contract_info_valid(self, asset: Asset): def __filter_modified_assets(self) -> list[Asset]: """Filter the modified assets.""" - # Get recent tag - recent_tag_result = run( - ["git", "describe", "--tags", "--abbrev=0", "HEAD^"], - stdout=PIPE, - stderr=PIPE, - text=True, - check=True, - ) - recent_tag = recent_tag_result.stdout.strip() - # Get modified files - diff_result = run( - ["git", "diff", "--name-only", recent_tag], - stdout=PIPE, - stderr=PIPE, - text=True, - check=True, - ) - changed_files = [ - file for file in diff_result.stdout.strip().split("\n") if file - ] + repo = Repo(".") + # noinspection PyUnresolvedReferences + main_branch = repo.branches["main"] + changed_files = [item.a_path for item in repo.index.diff(main_branch.commit)] asset_matches = [ search(r"assets/([^/]+)/info.json", file) for file in changed_files ] diff --git a/tests/conftest.py b/tests/conftest.py index e1c010a..7eda787 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -10,21 +10,30 @@ def pytest_addoption(parser: pytest.Parser): parser.addoption( "--skip-image-test", action="store_true", help="Skip the image test." ) + parser.addoption( + "--all", + action="store_true", + help="Run all tests.", + ) def pytest_configure(config: pytest.Config): config.addinivalue_line("markers", "rpc: Skip the RPC connection using test.") config.addinivalue_line("markers", "image: Skip the image test.") + config.addinivalue_line("markers", "all: Run all tests.") def pytest_collection_modifyitems(config: pytest.Config, items: list[pytest.Item]): - if config.getoption("--skip-rpc-using-test"): + if config.getoption("--all", default=False): + return + else: + skip_not_all = pytest.mark.skip(reason="Skip the test in all.") skip_rpc = pytest.mark.skip(reason="Skip the RPC connection using test.") - for item in items: - if "rpc" in item.keywords: - item.add_marker(skip_rpc) - if config.getoption("--skip-image-test"): skip_image = pytest.mark.skip(reason="Skip the image test.") for item in items: - if "image" in item.keywords: + if "all" in item.keywords: + item.add_marker(skip_not_all) + elif config.getoption("--skip-rpc-using-test") and "rpc" in item.keywords: + item.add_marker(skip_rpc) + elif config.getoption("--skip-image-test") and "image" in item.keywords: item.add_marker(skip_image)