pyrulesrunner


Namepyrulesrunner JSON
Version 1.0.3 PyPI version JSON
download
home_pagehttps://github.com/Pradeep241094/pythonrules
SummaryA lightweight Python test runner with method-level discovery and coverage reporting
upload_time2025-07-26 22:05:05
maintainerNone
docs_urlNone
authorPradeep Margasahayam Prakash
requires_python>=3.7
licenseNone
keywords testing test-runner unittest coverage lint python
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # PyRules Runner

A simple, efficient Python testing framework that provides test discovery at the method level, code coverage reporting, and basic linting capabilities. Unlike more complex testing frameworks, this lightweight solution focuses on simplicity and ease of use while still providing detailed test results.

## Features

- **Method-level test discovery**: Identifies individual test methods within unittest.TestCase classes
- **Multiple test types**: Support for unit, integration, end-to-end, and regression tests
- **Code coverage reporting**: Console and HTML coverage reports
- **Basic linting**: PEP8 style checking with flake8
- **Simple configuration**: JSON-based configuration for test groups and patterns
- **Clear reporting**: Emoji-enhanced console output with detailed error information
- **Easy installation**: Installable via pip with command-line interface

## Installation

### From PyPI (when published)

```bash
pip pyrulesrunner
```

### From PyPI (when published)

```bash
pip install pyrulesrunner
```

### From Source

```bash
git clone <repository-url>
cd pyrulesrunner
pip install -e .
```

### With Optional Dependencies

```bash
# Install with coverage support
pip install pyrulesrunner[coverage]

# Install with linting support
pip install pyrulesrunner[lint]

# Install with all optional features
pip install pyrulesrunner[all]
```

### Legacy Installation (Single File)

You can also use the standalone `testrules.py` script:

```bash
# Download testrules.py to your project
# Install dependencies
pip install coverage flake8
```

## Usage

After installation, you can use the `testrules` command from anywhere:

```bash
# Run all tests
testrules
testrules --all

# Run specific test types
testrules unit
testrules integration
testrules e2e
testrules regression

# Run specific modules
testrules test_module1 test_module2

# Run test groups (defined in config)
testrules core
testrules api

# Run linting only
testrules lint
testrules --lint-only

# Run comprehensive check (linting + all tests)
testrules check
testrules --check

# Use custom configuration
testrules --config my_config.json

# Disable coverage
testrules --no-coverage

# Show help
testrules --help
```

### Alternative Usage

You can also run it as a Python module:

```bash
python -m testrules --all
python -m testrules unit
```

### Legacy Usage (Single File)

If using the standalone script:

```bash
# Run all tests
python testrules.py

# Run specific test types
python testrules.py unit
python testrules.py integration
python testrules.py e2e
python testrules.py regression

# Run specific modules
python testrules.py test_module1 test_module2

# Run linting
python testrules.py lint
python testrules.py check
```

## Configuration

The test runner uses a `testrules.json` configuration file to define test patterns, groups, and settings:

```json
{
  "test_patterns": {
    "unit": ["test_*.py", "*_test.py", "unit_test_*.py"],
    "integration": ["integration_test_*.py", "*_integration_test.py"],
    "e2e": ["e2e_test_*.py", "*_e2e_test.py"],
    "regression": ["regression_test_*.py", "*_regression_test.py"]
  },
  "test_groups": {
    "all": [],
    "core": ["test_core1", "test_core2"],
    "api": ["test_api1", "test_api2"],
    "fast": ["test_quick1", "test_quick2"],
    "slow": ["test_slow1", "test_slow2"]
  },
  "coverage_enabled": true,
  "html_coverage": true,
  "html_coverage_dir": "htmlcov",
  "coverage_config": {
    "source": ["."],
    "omit": [
      "*/tests/*",
      "*/test_*",
      "*/__pycache__/*",
      "*/venv/*",
      "*/env/*",
      "setup.py"
    ]
  },
  "lint_config": {
    "enabled": true,
    "max_line_length": 88,
    "ignore": ["E203", "W503"]
  }
}
```

## Using in Your Project

1. **Install the package**:

   ```bash
   pip install pyrulesrunner[all]
   ```

2. **Create a `testrules.json` configuration file** in your project root:

   ```json
   {
     "test_patterns": {
       "unit": ["test_*.py", "*_test.py"],
       "integration": ["integration_*.py"],
       "e2e": ["e2e_*.py"]
     },
     "test_groups": {
       "fast": ["test_utils", "test_models"],
       "slow": ["test_integration", "test_e2e"]
     },
     "coverage_enabled": true,
     "html_coverage": true
   }
   ```

3. **Run your tests**:

   ```bash
   # Run all tests
   testrules

   # Run only fast tests
   testrules fast

   # Run unit tests with coverage
   testrules unit

   # Run tests and linting
   testrules check
   ```

## Example Output

```
๐Ÿš€ Lightweight Test Runner
==================================================
๐Ÿ“„ Loaded configuration from testrules.json
Command: all tests

๐Ÿ” Discovering tests...
๐Ÿ“ Found 4 test files

๐Ÿงช Discovering test methods...
๐ŸŽฏ Total test methods discovered: 15

๐Ÿš€ Running tests...
๐Ÿ“ฆ Running tests in module: test_calculator
  [1/15] test_calculator.TestCalculator.test_add ... โœ… PASS (0.001s)
  [2/15] test_calculator.TestCalculator.test_subtract ... โœ… PASS (0.001s)

============================================================
๐Ÿงช TEST SUMMARY
============================================================
โœ… Passed:        14
โŒ Failed:        1
๐Ÿ’ฅ Errors:        0
๐Ÿ“Š Total:         15
๐Ÿ“ˆ Success Rate:  93.33%
โฑ๏ธ  Execution Time: 0.05 seconds

๐Ÿ“Š COVERAGE REPORT
============================================================
Name                 Stmts   Miss  Cover
----------------------------------------
calculator.py           20      2    90%
utils.py               15      0   100%
----------------------------------------
TOTAL                   35      2    94%

โœ… All checks passed successfully!
```

## Writing Tests

The test runner works with standard Python unittest framework:

```python
import unittest

class TestExample(unittest.TestCase):
    def test_addition(self):
        """Test basic addition."""
        self.assertEqual(2 + 2, 4)

    def test_subtraction(self):
        """Test basic subtraction."""
        self.assertEqual(5 - 3, 2)

if __name__ == '__main__':
    unittest.main()
```

## Test Types

### Unit Tests

- File patterns: `test_*.py`, `*_test.py`, `unit_test_*.py`
- Purpose: Test individual functions or classes in isolation
- Example: `test_calculator.py`

### Integration Tests

- File patterns: `integration_test_*.py`, `*_integration_test.py`
- Purpose: Test interaction between multiple components
- Example: `integration_test_database.py`

### End-to-End Tests

- File patterns: `e2e_test_*.py`, `*_e2e_test.py`
- Purpose: Test complete user workflows
- Example: `e2e_test_user_registration.py`

### Regression Tests

- File patterns: `regression_test_*.py`, `*_regression_test.py`
- Purpose: Test previously fixed bugre they don't reoccur
- Example: `regression_test_issue_123.py`

## Programmatic Usage

You can also use the test runner programmatically:

```python
from testrules import TestRunner, Config

# Create configuration
config = Config({
    "test_patterns": {
        "unit": ["test_*.py"]
    },
    "coverage_enabled": True
})

# Create and run test runner
runner = TestRunner(config)
test_results, coverage_obj = runner.run_tests(test_type="unit")

print(f"Tests run: {test_results.total}")
print(f"Passed: {test_results.passed}")
print(f"Failed: {test_results.failed}")
```

## Project Structure

```
your_project/
โ”œโ”€โ”€ testrules.json           # Configuration file (optional)
โ”œโ”€โ”€ src/                     # Your source code
โ”‚   โ”œโ”€โ”€ module1.py
โ”‚   โ””โ”€โ”€ module2.py
โ”œโ”€โ”€ tests/                   # Your test files
โ”‚   โ”œโ”€โ”€ test_module1.py      # Unit tests
โ”‚   โ”œโ”€โ”€ test_module2.py      # Unit tests
โ”‚   โ”œโ”€โ”€ integration_test_api.py    # Integration tests
โ”‚   โ”œโ”€โ”€ e2e_test_workflow.py       # End-to-end tests
โ”‚   โ””โ”€โ”€ regression_test_bug_fix.py # Regression tests
โ””โ”€โ”€ htmlcov/                 # HTML coverage reports (generated)
```

## Development

To contribute to the project:

```bash
git clone <repository-url>
cd pyrulesrunner
pip install -e .[dev]

# Run the test runner's own tests
testrules test_testrules

# Run all example tests
testrules comprehensive
```

## Requirements

- Python 3.7+
- Optional: `coverage>=6.0` for coverage reporting
- Optional: `flake8>=4.0` for linting

## Troubleshooting

### Common Issues

1. **Module Import Errors**

   - Ensure your test files are in the Python path
   - Check that all dependencies are installed
   - Verify file names match the expected patterns

2. **Coverage Not Working**

   - Install coverage: `pip install pyrulesrunner[coverage]`
   - Ensure coverage is enabled in configuration

3. **Linting Not Working**
   - Install flake8: `pip install pyrulesrunner[lint]`
   - Check that your Python files are accessible

### Getting Help

If you encounter issues:

1. Check that all dependencies are installed
2. Verify your test file naming follows the expected patterns
3. Ensure your test files contain valid unittest.TestCase classes
4. Check the configuration file syntax if using custom settings

## Contributing

This is a lightweight test runner designed for simplicity. If you need more advanced features, consider using pytest or other full-featured testing frameworks.

## License

This project is open source under the MIT License. Feel free to modify and distribut



            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/Pradeep241094/pythonrules",
    "name": "pyrulesrunner",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": null,
    "keywords": "testing test-runner unittest coverage lint python",
    "author": "Pradeep Margasahayam Prakash",
    "author_email": "pradeepprakash1024@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/51/34/6d1a002e930ea72fdd94f67e808c300fffd44b39e1d5c21d292dec3673c7/pyrulesrunner-1.0.3.tar.gz",
    "platform": null,
    "description": "# PyRules Runner\n\nA simple, efficient Python testing framework that provides test discovery at the method level, code coverage reporting, and basic linting capabilities. Unlike more complex testing frameworks, this lightweight solution focuses on simplicity and ease of use while still providing detailed test results.\n\n## Features\n\n- **Method-level test discovery**: Identifies individual test methods within unittest.TestCase classes\n- **Multiple test types**: Support for unit, integration, end-to-end, and regression tests\n- **Code coverage reporting**: Console and HTML coverage reports\n- **Basic linting**: PEP8 style checking with flake8\n- **Simple configuration**: JSON-based configuration for test groups and patterns\n- **Clear reporting**: Emoji-enhanced console output with detailed error information\n- **Easy installation**: Installable via pip with command-line interface\n\n## Installation\n\n### From PyPI (when published)\n\n```bash\npip pyrulesrunner\n```\n\n### From PyPI (when published)\n\n```bash\npip install pyrulesrunner\n```\n\n### From Source\n\n```bash\ngit clone <repository-url>\ncd pyrulesrunner\npip install -e .\n```\n\n### With Optional Dependencies\n\n```bash\n# Install with coverage support\npip install pyrulesrunner[coverage]\n\n# Install with linting support\npip install pyrulesrunner[lint]\n\n# Install with all optional features\npip install pyrulesrunner[all]\n```\n\n### Legacy Installation (Single File)\n\nYou can also use the standalone `testrules.py` script:\n\n```bash\n# Download testrules.py to your project\n# Install dependencies\npip install coverage flake8\n```\n\n## Usage\n\nAfter installation, you can use the `testrules` command from anywhere:\n\n```bash\n# Run all tests\ntestrules\ntestrules --all\n\n# Run specific test types\ntestrules unit\ntestrules integration\ntestrules e2e\ntestrules regression\n\n# Run specific modules\ntestrules test_module1 test_module2\n\n# Run test groups (defined in config)\ntestrules core\ntestrules api\n\n# Run linting only\ntestrules lint\ntestrules --lint-only\n\n# Run comprehensive check (linting + all tests)\ntestrules check\ntestrules --check\n\n# Use custom configuration\ntestrules --config my_config.json\n\n# Disable coverage\ntestrules --no-coverage\n\n# Show help\ntestrules --help\n```\n\n### Alternative Usage\n\nYou can also run it as a Python module:\n\n```bash\npython -m testrules --all\npython -m testrules unit\n```\n\n### Legacy Usage (Single File)\n\nIf using the standalone script:\n\n```bash\n# Run all tests\npython testrules.py\n\n# Run specific test types\npython testrules.py unit\npython testrules.py integration\npython testrules.py e2e\npython testrules.py regression\n\n# Run specific modules\npython testrules.py test_module1 test_module2\n\n# Run linting\npython testrules.py lint\npython testrules.py check\n```\n\n## Configuration\n\nThe test runner uses a `testrules.json` configuration file to define test patterns, groups, and settings:\n\n```json\n{\n  \"test_patterns\": {\n    \"unit\": [\"test_*.py\", \"*_test.py\", \"unit_test_*.py\"],\n    \"integration\": [\"integration_test_*.py\", \"*_integration_test.py\"],\n    \"e2e\": [\"e2e_test_*.py\", \"*_e2e_test.py\"],\n    \"regression\": [\"regression_test_*.py\", \"*_regression_test.py\"]\n  },\n  \"test_groups\": {\n    \"all\": [],\n    \"core\": [\"test_core1\", \"test_core2\"],\n    \"api\": [\"test_api1\", \"test_api2\"],\n    \"fast\": [\"test_quick1\", \"test_quick2\"],\n    \"slow\": [\"test_slow1\", \"test_slow2\"]\n  },\n  \"coverage_enabled\": true,\n  \"html_coverage\": true,\n  \"html_coverage_dir\": \"htmlcov\",\n  \"coverage_config\": {\n    \"source\": [\".\"],\n    \"omit\": [\n      \"*/tests/*\",\n      \"*/test_*\",\n      \"*/__pycache__/*\",\n      \"*/venv/*\",\n      \"*/env/*\",\n      \"setup.py\"\n    ]\n  },\n  \"lint_config\": {\n    \"enabled\": true,\n    \"max_line_length\": 88,\n    \"ignore\": [\"E203\", \"W503\"]\n  }\n}\n```\n\n## Using in Your Project\n\n1. **Install the package**:\n\n   ```bash\n   pip install pyrulesrunner[all]\n   ```\n\n2. **Create a `testrules.json` configuration file** in your project root:\n\n   ```json\n   {\n     \"test_patterns\": {\n       \"unit\": [\"test_*.py\", \"*_test.py\"],\n       \"integration\": [\"integration_*.py\"],\n       \"e2e\": [\"e2e_*.py\"]\n     },\n     \"test_groups\": {\n       \"fast\": [\"test_utils\", \"test_models\"],\n       \"slow\": [\"test_integration\", \"test_e2e\"]\n     },\n     \"coverage_enabled\": true,\n     \"html_coverage\": true\n   }\n   ```\n\n3. **Run your tests**:\n\n   ```bash\n   # Run all tests\n   testrules\n\n   # Run only fast tests\n   testrules fast\n\n   # Run unit tests with coverage\n   testrules unit\n\n   # Run tests and linting\n   testrules check\n   ```\n\n## Example Output\n\n```\n\ud83d\ude80 Lightweight Test Runner\n==================================================\n\ud83d\udcc4 Loaded configuration from testrules.json\nCommand: all tests\n\n\ud83d\udd0d Discovering tests...\n\ud83d\udcc1 Found 4 test files\n\n\ud83e\uddea Discovering test methods...\n\ud83c\udfaf Total test methods discovered: 15\n\n\ud83d\ude80 Running tests...\n\ud83d\udce6 Running tests in module: test_calculator\n  [1/15] test_calculator.TestCalculator.test_add ... \u2705 PASS (0.001s)\n  [2/15] test_calculator.TestCalculator.test_subtract ... \u2705 PASS (0.001s)\n\n============================================================\n\ud83e\uddea TEST SUMMARY\n============================================================\n\u2705 Passed:        14\n\u274c Failed:        1\n\ud83d\udca5 Errors:        0\n\ud83d\udcca Total:         15\n\ud83d\udcc8 Success Rate:  93.33%\n\u23f1\ufe0f  Execution Time: 0.05 seconds\n\n\ud83d\udcca COVERAGE REPORT\n============================================================\nName                 Stmts   Miss  Cover\n----------------------------------------\ncalculator.py           20      2    90%\nutils.py               15      0   100%\n----------------------------------------\nTOTAL                   35      2    94%\n\n\u2705 All checks passed successfully!\n```\n\n## Writing Tests\n\nThe test runner works with standard Python unittest framework:\n\n```python\nimport unittest\n\nclass TestExample(unittest.TestCase):\n    def test_addition(self):\n        \"\"\"Test basic addition.\"\"\"\n        self.assertEqual(2 + 2, 4)\n\n    def test_subtraction(self):\n        \"\"\"Test basic subtraction.\"\"\"\n        self.assertEqual(5 - 3, 2)\n\nif __name__ == '__main__':\n    unittest.main()\n```\n\n## Test Types\n\n### Unit Tests\n\n- File patterns: `test_*.py`, `*_test.py`, `unit_test_*.py`\n- Purpose: Test individual functions or classes in isolation\n- Example: `test_calculator.py`\n\n### Integration Tests\n\n- File patterns: `integration_test_*.py`, `*_integration_test.py`\n- Purpose: Test interaction between multiple components\n- Example: `integration_test_database.py`\n\n### End-to-End Tests\n\n- File patterns: `e2e_test_*.py`, `*_e2e_test.py`\n- Purpose: Test complete user workflows\n- Example: `e2e_test_user_registration.py`\n\n### Regression Tests\n\n- File patterns: `regression_test_*.py`, `*_regression_test.py`\n- Purpose: Test previously fixed bugre they don't reoccur\n- Example: `regression_test_issue_123.py`\n\n## Programmatic Usage\n\nYou can also use the test runner programmatically:\n\n```python\nfrom testrules import TestRunner, Config\n\n# Create configuration\nconfig = Config({\n    \"test_patterns\": {\n        \"unit\": [\"test_*.py\"]\n    },\n    \"coverage_enabled\": True\n})\n\n# Create and run test runner\nrunner = TestRunner(config)\ntest_results, coverage_obj = runner.run_tests(test_type=\"unit\")\n\nprint(f\"Tests run: {test_results.total}\")\nprint(f\"Passed: {test_results.passed}\")\nprint(f\"Failed: {test_results.failed}\")\n```\n\n## Project Structure\n\n```\nyour_project/\n\u251c\u2500\u2500 testrules.json           # Configuration file (optional)\n\u251c\u2500\u2500 src/                     # Your source code\n\u2502   \u251c\u2500\u2500 module1.py\n\u2502   \u2514\u2500\u2500 module2.py\n\u251c\u2500\u2500 tests/                   # Your test files\n\u2502   \u251c\u2500\u2500 test_module1.py      # Unit tests\n\u2502   \u251c\u2500\u2500 test_module2.py      # Unit tests\n\u2502   \u251c\u2500\u2500 integration_test_api.py    # Integration tests\n\u2502   \u251c\u2500\u2500 e2e_test_workflow.py       # End-to-end tests\n\u2502   \u2514\u2500\u2500 regression_test_bug_fix.py # Regression tests\n\u2514\u2500\u2500 htmlcov/                 # HTML coverage reports (generated)\n```\n\n## Development\n\nTo contribute to the project:\n\n```bash\ngit clone <repository-url>\ncd pyrulesrunner\npip install -e .[dev]\n\n# Run the test runner's own tests\ntestrules test_testrules\n\n# Run all example tests\ntestrules comprehensive\n```\n\n## Requirements\n\n- Python 3.7+\n- Optional: `coverage>=6.0` for coverage reporting\n- Optional: `flake8>=4.0` for linting\n\n## Troubleshooting\n\n### Common Issues\n\n1. **Module Import Errors**\n\n   - Ensure your test files are in the Python path\n   - Check that all dependencies are installed\n   - Verify file names match the expected patterns\n\n2. **Coverage Not Working**\n\n   - Install coverage: `pip install pyrulesrunner[coverage]`\n   - Ensure coverage is enabled in configuration\n\n3. **Linting Not Working**\n   - Install flake8: `pip install pyrulesrunner[lint]`\n   - Check that your Python files are accessible\n\n### Getting Help\n\nIf you encounter issues:\n\n1. Check that all dependencies are installed\n2. Verify your test file naming follows the expected patterns\n3. Ensure your test files contain valid unittest.TestCase classes\n4. Check the configuration file syntax if using custom settings\n\n## Contributing\n\nThis is a lightweight test runner designed for simplicity. If you need more advanced features, consider using pytest or other full-featured testing frameworks.\n\n## License\n\nThis project is open source under the MIT License. Feel free to modify and distribut\n\n\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "A lightweight Python test runner with method-level discovery and coverage reporting",
    "version": "1.0.3",
    "project_urls": {
        "Bug Reports": "https://github.com/Pradeep241094/pythonrules/issues",
        "Documentation": "https://github.com/Pradeep241094/pythonrules#readme",
        "Homepage": "https://github.com/Pradeep241094/pythonrules",
        "Source": "https://github.com/Pradeep241094/pythonrules"
    },
    "split_keywords": [
        "testing",
        "test-runner",
        "unittest",
        "coverage",
        "lint",
        "python"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "68599db9da1fa43e031b0d897ae067aef8091302fd758b7dad4e6e3880212d08",
                "md5": "79783d6dd3d897a881a0471c9e0c58a6",
                "sha256": "38c0591c6fdfe985c1a499829611270d8fe6a26f45b00f717e297bc7833aa7fc"
            },
            "downloads": -1,
            "filename": "pyrulesrunner-1.0.3-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "79783d6dd3d897a881a0471c9e0c58a6",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 22217,
            "upload_time": "2025-07-26T22:05:04",
            "upload_time_iso_8601": "2025-07-26T22:05:04.206954Z",
            "url": "https://files.pythonhosted.org/packages/68/59/9db9da1fa43e031b0d897ae067aef8091302fd758b7dad4e6e3880212d08/pyrulesrunner-1.0.3-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "51346d1a002e930ea72fdd94f67e808c300fffd44b39e1d5c21d292dec3673c7",
                "md5": "17b0186fca19039e8c69c8d46a34aa51",
                "sha256": "072833cdb63eee80cb15c10af3015d108f0cfbe6973d1b07bfcf524a2186feeb"
            },
            "downloads": -1,
            "filename": "pyrulesrunner-1.0.3.tar.gz",
            "has_sig": false,
            "md5_digest": "17b0186fca19039e8c69c8d46a34aa51",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 19800,
            "upload_time": "2025-07-26T22:05:05",
            "upload_time_iso_8601": "2025-07-26T22:05:05.445082Z",
            "url": "https://files.pythonhosted.org/packages/51/34/6d1a002e930ea72fdd94f67e808c300fffd44b39e1d5c21d292dec3673c7/pyrulesrunner-1.0.3.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-07-26 22:05:05",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "Pradeep241094",
    "github_project": "pythonrules",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "pyrulesrunner"
}
        
Elapsed time: 1.19443s