Skip to main content

LLM-powered automatic test generation for Python

Project description

earlyai-agent

AI-powered automatic unit test generation for Python, by Early.

earlyai-agent is the Python analysis engine used by the Early CLI to generate green (passing) unit tests. It analyzes your source code, identifies public functions and methods, and generates pytest tests using AI.

Note: earlyai-agent is a dependency of the Early CLI and is not intended to be used standalone. Install and operate it through the Early CLI.

Installation

1. Install the Early CLI

npm install -g @earlyai/cli

See the CLI Installation Guide for details.

2. Install earlyai-agent

pip install earlyai-agent

Requirements: Python 3.11+

3. Get an API Key

You need an EarlyAI API key to use the agent. Contact support@startearly.ai or visit www.startearly.ai to get one.

Usage

All commands are run through the Early CLI. See the full CLI documentation for all options.

Generate tests for a project

early generate-project \
  --api-key <your-api-key> \
  --token <your-github-token> \
  --target-directory src/ \
  --ref-name <branch-name> \
  --test-framework pytest

See the Repo CLI Guide for more details.

Generate tests on a pull request

early generate-pr \
  --api-key <your-api-key> \
  --token <your-github-token> \
  --pr-number 123 \
  --ref-name feature/my-branch \
  --test-framework pytest

See the PR CLI Guide for more details.

Run locally

For quick local evaluation, see Running Early CLI Locally.

Configuration

All options can be set via CLI flags or environment variables:

Flag Env Variable Default Description
--api-key API_KEY -- EarlyAI API key (required)
--token TOKEN -- GitHub token for commits/PRs (required)
--target-directory TARGET_DIRECTORY . File or directory to generate tests for
--test-framework TEST_FRAMEWORK pytest Test framework (pytest)
--test-structure TEST_STRUCTURE siblingFolder Where to place tests (siblingFolder, rootFolder)
--max-concurrency MAX_CONCURRENCY 3 Number of concurrent workers
--max-testables MAX_TESTABLES unlimited Max methods to generate tests for

For the full configuration reference, see CLI Configuration.

Test file placement

  • siblingFolder (default): Tests are placed in a folder next to the source file
    src/services/user.py
    src/services/user.early.test/test_get_user.py
    
  • rootFolder: Tests are placed in a root tests/ directory mirroring the source structure

CI/CD Integration

GitHub Actions (PR)

Add to .github/workflows/early-pr-test-generation.yml:

name: Early PR Test Generation

permissions:
  contents: write
  pull-requests: write
  packages: read

on:
  pull_request:
    types: [opened, reopened, synchronize]
    branches: [main]

jobs:
  early-test-generation:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
        with:
          ref: ${{ github.head_ref }}

      - uses: actions/setup-python@v5
        with:
          python-version: "3.11"

      - uses: actions/setup-node@v4
        with:
          node-version: 20

      - name: Install dependencies
        run: |
          pip install earlyai-agent
          npm install -g @earlyai/cli

      - name: Generate tests
        continue-on-error: true
        env:
          API_KEY: ${{ secrets.EARLY_AGENT_API_KEY }}
          TOKEN: ${{ secrets.GITHUB_TOKEN }}
          PR_NUMBER: ${{ github.event.pull_request.number }}
          REF_NAME: ${{ github.head_ref }}
          BASE_REF: ${{ github.base_ref }}
          TEST_FRAMEWORK: pytest
        run: early generate-pr

For other CI/CD systems (Jenkins, CircleCI, Bitbucket Pipelines), see the Agent Onboarding Guide.

How It Works

  1. Scan -- Discovers Python source files in the target directory
  2. Extract -- Analyzes each file to identify public functions and methods
  3. Generate -- Uses AI to generate unit tests for each function
  4. Validate -- Runs generated tests with pytest, keeping only green (passing) tests

Troubleshooting

Support

License

Commercial

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

earlyai_agent-0.2.5.tar.gz (56.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

earlyai_agent-0.2.5-py3-none-any.whl (76.1 kB view details)

Uploaded Python 3

File details

Details for the file earlyai_agent-0.2.5.tar.gz.

File metadata

  • Download URL: earlyai_agent-0.2.5.tar.gz
  • Upload date:
  • Size: 56.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.14

File hashes

Hashes for earlyai_agent-0.2.5.tar.gz
Algorithm Hash digest
SHA256 df9d687b84dc0b990f2be39c071ec9ea6a1b97d6deabd5ec61df1cddcc8cbd0b
MD5 2f55f1cf55025585dc5bc6e56d0d9e71
BLAKE2b-256 0c90ade2df7e37e66714ed0d770988eb2ebc09a73e515a6a23f80b6684cd6f2e

See more details on using hashes here.

File details

Details for the file earlyai_agent-0.2.5-py3-none-any.whl.

File metadata

  • Download URL: earlyai_agent-0.2.5-py3-none-any.whl
  • Upload date:
  • Size: 76.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.14

File hashes

Hashes for earlyai_agent-0.2.5-py3-none-any.whl
Algorithm Hash digest
SHA256 65ee15297626d2a12c305de9419de6b2244b4a06e71390721ba9cdd056b9918a
MD5 45c3730f732de0d4aea0c433ecf143ce
BLAKE2b-256 ba85ca172f9771faffc46fcd648c2e65f84f15a401be37c2d0af49481ef5799e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page