Skip to content

Commit

Permalink
add flag for subset of tests
Browse files Browse the repository at this point in the history
  • Loading branch information
varun646 committed Aug 23, 2024
1 parent 427acbd commit 0bdc51e
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .github/workflows/standard.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,4 @@ jobs:
- name: Test with pytest
run: |
pip install pytest pytest-cov
pytest tests/test_generation.py --doctest-modules --junitxml=junit/test-results.xml --cov=com --cov-report=xml --cov-report=html -n auto
pytest tests/test_generation.py --doctest-modules --junitxml=junit/test-results.xml --cov=com --cov-report=xml --cov-report=html --subset-percentage 0.1
27 changes: 27 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import random


def pytest_addoption(parser):
parser.addoption(
"--subset-percentage",
action="store",
default=None,
help="Specify the percentage of tests to run as a subset (e.g., 0.3 for 30%)",
)


def pytest_collection_modifyitems(config, items):
subset_percentage = config.getoption("--subset-percentage")

# If the subset percentage is provided, apply it
if subset_percentage is not None:
subset_percentage = float(subset_percentage)

# Shuffle the test cases
random.shuffle(items)

# Calculate the number of tests to run based on percentage
subset_count = int(len(items) * subset_percentage)

# Select a subset of tests
items[:] = items[:subset_count]

0 comments on commit 0bdc51e

Please sign in to comment.