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 details)

Uploaded Source

Built Distribution

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

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

Uploaded Python 3

File details

Details for the file unittest_gpt-0.1.3.tar.gz.

File metadata

  • Download URL: unittest_gpt-0.1.3.tar.gz
  • Upload date:
  • Size: 6.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.5.0 CPython/3.11.3 Darwin/22.1.0

File hashes

Hashes for unittest_gpt-0.1.3.tar.gz
Algorithm Hash digest
SHA256 fa06fd32b4692fdcb3a8e67bb066d8854f8145021cd1999014b7bc4b87f31f29
MD5 bc7b1f4d8da1d629ca757b407cce0846
BLAKE2b-256 5d1fac8ee64b2d7559db58b785ad77656ea555ca9994926c0c61e180b33b9464

See more details on using hashes here.

File details

Details for the file unittest_gpt-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: unittest_gpt-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 7.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.5.0 CPython/3.11.3 Darwin/22.1.0

File hashes

Hashes for unittest_gpt-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 d5e2a4aa06f8774268465669824eb5672b4df27e450321721a38a670d904b166
MD5 0134c07d9b6a84e20d668d66883d35be
BLAKE2b-256 363f49e6ffd2cbae915f44f76a5a07f560712a92a70439c69086a69b1e45d8bd

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