Skip to content

Commit

Permalink
STR-904: Split functional tests into folders. (#621)
Browse files Browse the repository at this point in the history
* Update flexitest.

* Introduce arguments for the functional tests.

* Split functional tests into groups(folders).

* Review fixes.
  • Loading branch information
evgenyzdanovich authored Jan 21, 2025
1 parent 0b95cf0 commit bf9ab51
Show file tree
Hide file tree
Showing 30 changed files with 139 additions and 17 deletions.
23 changes: 20 additions & 3 deletions functional-tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,16 +79,33 @@ You can run all tests:
./run_test.sh
```

Or, you can run a specific test:
You also can run a specific test:

```bash
./run_test.sh fn_bridge_deposit_happy
./run_test.sh -t tests/bridge/bridge_deposit_happy.py
```

Or (shorter version),

```bash
./run_test.sh -t bridge/bridge_deposit_happy.py
```

Or, you can run a specific test group:

```bash
./run_test.sh -g bridge
```

The full list of arguments for running tests can be viewed by:
```bash
./run_test.sh -h
```

## Running prover tasks

```bash
PROVER_TEST=1 ./run_test.sh fn_prover_client.py
PROVER_TEST=1 ./run_test.sh -g prover
```

The test harness script will be extended with more functionality as we need it.
62 changes: 52 additions & 10 deletions functional-tests/entry.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env python3

import argparse
import os
import sys

Expand All @@ -10,19 +11,60 @@
from utils import *
from utils.constants import *

TEST_DIR: str = "tests"

# Initialize the parser with arguments.
parser = argparse.ArgumentParser(prog="entry.py")
parser.add_argument("-g", "--groups", nargs="*", help="Define the test groups to execute")
parser.add_argument("-t", "--tests", nargs="*", help="Define individual tests to execute")


def filter_tests(parsed_args, modules):
"""
Filters test modules against parsed args supplied from the command line.
"""

arg_groups = frozenset(parsed_args.groups or [])
# Extract filenames from the tests paths.
arg_tests = frozenset(
[os.path.split(t)[1].removesuffix(".py") for t in parsed_args.tests or []]
)

filtered = dict()
for test, path in modules.items():
# Drop the prefix of the path before TEST_DIR
test_path_parts = os.path.normpath(path).split(os.path.sep)
# idx should never be None because TEST_DIR should be in the path.
idx = next((i for i, part in enumerate(test_path_parts) if part == TEST_DIR), None)
test_path_parts = test_path_parts[idx + 1 :]
# The "groups" the current test belongs to.
test_groups = frozenset(test_path_parts[:-1])

# Filtering logic:
# if groups or tests were specified (non-empty) as args, then check for exclusion
take = True
if arg_groups and not (arg_groups & test_groups):
take = False
if arg_tests and test not in arg_tests:
take = False

if take:
filtered[test] = path

return filtered


def main(argv):
"""
The main entrypoint for running functional tests.
"""

parsed_args = parser.parse_args(argv[1:])

root_dir = os.path.dirname(os.path.abspath(__file__))
test_dir = os.path.join(root_dir, "tests")
modules = flexitest.runtime.scan_dir_for_modules(test_dir)
all_tests = flexitest.runtime.load_candidate_modules(modules)

if len(argv) > 1:
# Run the specific test file passed as the first argument (without .py extension)
tests = [str(tst).removesuffix(".py").removeprefix("tests/") for tst in argv[1:]]
else:
# Run all tests
tests = all_tests
test_dir = os.path.join(root_dir, TEST_DIR)
modules = filter_tests(parsed_args, flexitest.runtime.scan_dir_for_modules(test_dir))
tests = flexitest.runtime.load_candidate_modules(modules)

btc_fac = factory.BitcoinFactory([12300 + i for i in range(100)])
seq_fac = factory.StrataFactory([12400 + i for i in range(100)])
Expand Down
71 changes: 67 additions & 4 deletions functional-tests/poetry.lock

Large diffs are not rendered by default.

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit bf9ab51

Please sign in to comment.