Skip to main content

Auto generate unit test using PyTest and Gpt

Project description


unittest-gpt

📍 Test smarter, not harder with unittest-gpt: GPT-powered auto unit tests generator!

⚙️ Developed with the software and tools below:

⚙️ Powered by OpenAI's GPT language model APIs and the software below:

🦜️🔗 OpenAI Python pytest


📚 Table of Contents


📍 Overview

unittest-gpt is a powerful, user-friendly tool that automatically generates unit test files for your python repositories using OpenAI's language model APIs. By simply providing the file or a directory, unittest-gpt will automatically generate unit test for your python source code.


🚀 Getting Started

✅ Prerequisites

Before you begin, ensure that you have the following prerequisites installed:

  • 📌 OPENAI - API KEY
  • 📌 Python 3.11

🔐 OpenAI API Setup

To use README-AI, you will need an API key for OpenAI. Follow the steps below to create an API key:

User Guide - OpenAI API
  1. Go to the OpenAI website.
  2. Click the "Sign up for free" button.
  3. Fill out the registration form with your information and agree to the terms of service.
  4. Once logged in, click on the "API" tab.
  5. Follow the instructions to create a new API key.
  6. Copy the API key and keep it in a secure place.

🖥 Installation

  1. Clone the unittest-gpt repository:
git clone ../unittest-gpt
  1. Change to the project directory:
cd unittest-gpt
  1. Setup up a venv (the least resistance way to get started quickly)
    1. if you don't have virtualenv install run the first command
pip install virtualenv 

virtualenv venv

source venv/bin/activate
  1. Install the dependencies:
pip install -r requirements.txt

🤖 Using unittest-gpt as cli

python unit_test_agent.py -f <file_name>
python unit_test_agent.py -dir <dir_name>
#example
python unit_test_agent.py -f test.py
python unit_test_agent.py -dir src

🤖 Using unittest-gpt in your project

unit_test_agent = UnitTestAgent()
# Call the method with the file parameter
unit_test_agent.generate_testcases(file="<file_name>")
# Call the method with the directory parameter
unit_test_agent.generate_testcases(path="<directory>")

🧪 Running Tests

Run below command in the root directory

pytest

🤝 Contributing

Contributions are always welcome! Please follow these steps:

  1. Fork the project repository. This creates a copy of the project on your account that you can modify without affecting the original project.
  2. Clone the forked repository to your local machine using a Git client like Git or GitHub Desktop.
  3. Create a new branch with a descriptive name (e.g., new-feature-branch or bugfix-issue-123).
git checkout -b new-feature-branch
  1. Make changes to the project's codebase.
  2. Commit your changes to your local branch with a clear commit message that explains the changes you've made.
git commit -m 'Implemented new feature.'
  1. Push your changes to your forked repository on GitHub using the following command
git push origin new-feature-branch
  1. Create a pull request to the original repository. Open a new pull request to the original project repository. In the pull request, describe the changes you've made and why they're necessary. The project maintainers will review your changes and provide feedback or merge them into the main branch.

📄 License

This project is licensed under the MIT License License. See the LICENSE file for additional info.


👏 Acknowledgments


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

unittest_gpt-0.1.3.tar.gz (6.9 kB view hashes)

Uploaded Source

Built Distribution

unittest_gpt-0.1.3-py3-none-any.whl (7.6 kB view hashes)

Uploaded Python 3

Supported by

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