{"id":23173460,"url":"https://github.com/kivanc57/pytesting","last_synced_at":"2025-04-05T00:24:55.521Z","repository":{"id":262014585,"uuid":"885885915","full_name":"kivanc57/pytesting","owner":"kivanc57","description":"This repository demonstrates pytest testing techniques, including fixtures, mocking, and parametrization, with tests for operations and custom classes.","archived":false,"fork":false,"pushed_at":"2025-01-13T21:34:25.000Z","size":40,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-10T08:49:12.504Z","etag":null,"topics":["class","mock-testing","parametrized-tests","pytest","python","python3","testing"],"latest_commit_sha":null,"homepage":"https://www.freecodecamp.org/news/testing-in-python-with-pytest/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kivanc57.png","metadata":{"files":{"readme":"READMe.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-11-09T16:45:46.000Z","updated_at":"2025-01-13T21:34:28.000Z","dependencies_parsed_at":null,"dependency_job_id":"2fbdb3b4-566a-4522-b262-3041b61b3f6a","html_url":"https://github.com/kivanc57/pytesting","commit_stats":null,"previous_names":["kivanc57/pytest_testing","kivanc57/pytesting"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kivanc57%2Fpytesting","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kivanc57%2Fpytesting/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kivanc57%2Fpytesting/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kivanc57%2Fpytesting/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kivanc57","download_url":"https://codeload.github.com/kivanc57/pytesting/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247268106,"owners_count":20911081,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["class","mock-testing","parametrized-tests","pytest","python","python3","testing"],"created_at":"2024-12-18T05:16:05.876Z","updated_at":"2025-04-05T00:24:55.504Z","avatar_url":"https://github.com/kivanc57.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Pytesting 🧪\n\nThis repository provides a comprehensive testing suite for validating geometric shapes, mathematical functions, and a fictional Hogwarts-themed classroom model. With a set of pre-defined tests, mocks, and parameterizations, this project demonstrates extensive testing using `Pytest`.\n\n─── ⋆⋅☆⋅⋆ ─────────────────────────────────────────────────────\n\n## Table of Contents\n- [🏗️ Project Structure](#project-structure)\n- [🚀 Installation](#installation)\n- [🛠️ Usage and Execution](#usage-and-execution)\n- [🔬 Testing Components](#testing-components)\n- [🔎 Sample Code and Fixtures](#sample-code-and-fixtures)\n- [🧩 Notes](#notes)\n- [⚙️ Requirements](#requirements)\n- [🤝 Contributing](#contributing)\n- [📜 License](#license)\n- [📬 Contact](#contact)\n\n─── ⋆⋅☆⋅⋆ ─────────────────────────────────────────────────────\n\n# 🏗️ Project Structure \u003ca id=\"project-structure\"\u003e\u003c/a\u003e\n```markdown\n📁 project-root\n├── 📁 source\n│ ├── 📄 __init__.py\n│ ├── 📄 functions.py\n│ ├── 📄 school.py\n│ ├── 📄 service.py\n│ └── 📄 shapes.py\n│\n├── 📁 tests\n│ ├── 📄 __init__.py\n│ ├── 📄 conftest.py\n│ ├── 📄 test_Circle.py\n│ ├── 📄 test_functions.py\n│ ├── 📄 test_Rectangle.py\n│ ├── 📄 test_school.py\n│ ├── 📄 test_service.py\n│ └── 📄 test_Square.py\n│\n├── 📄 .gitignore\n├── 📄 .gitattributes\n├── 📄 requirements.txt\n└── 📄 test_commands.txt\n```\n\n─── ⋆⋅☆⋅⋆ ─────────────────────────────────────────────────────\n\n## 🚀 Installation \u003ca id=\"installation\"\u003e\u003c/a\u003e\n\n1. **Clone the repository:**\n   ```bash\n   git clone https://github.com/kivanc57/pytesting\n   cd pytesting\n   ```\n\n2. **Set up the virtual environment:**\n    ``` python\n    python3 -m venv venv\n    source venv/bin/activate   # On Windows, use `venv\\Scripts\\activate`\n\n3. Install dependencies:\n    ``` python\n    pip install -r requirements.txt\n    ```\n\n─── ⋆⋅☆⋅⋆ ─────────────────────────────────────────────────────\n\n## 🛠️ Usage and Execution \u003ca id=\"usage-and-execution\"\u003e\u003c/a\u003e\n### Running Tests\nThe testing suite is built with Pytest and can be executed with various options:\n\nRun all tests:\n``` bash\npytest\n```\n\nRun tests with verbose output:\n``` bash\npytest -v\n```\n\nRun specific tests (e.g., slow tests):\n``` bash\npytest -m slow\n```\n\n### Mock Tests\nMocks are utilized in this project to simulate external calls (e.g., API requests) and avoid dependencies on real databases or services.\n\n### Parameterized Tests\nThis project also employs parameterized testing for the shapes module, allowing multiple test cases with different inputs.\n\n─── ⋆⋅☆⋅⋆ ─────────────────────────────────────────────────────\n\n## 🔬 Testing Components \u003ca id=\"testing-components\"\u003e\u003c/a\u003e\n### **Shapes Module Tests**\n Tests cover various shapes, including:\n\n- 🔷 **Rectangle** 🔷\n  \n  Validates `area()` and `perimeter()` methods, ensuring correct calculations.\n\n- 🔴 **Circle** 🔴\n\n  Checks `area()` and `perimeter()` for circular dimensions.\n\n\n- 🟩 **Square** 🟩\n\n  Uses parameterized testing to validate multiple `side_length`s.\n\n### Classroom Module Tests\nSimulates a Hogwarts-style classroom:\n\n- 🏫 **Classroom Initialization** 🏫\n\n  Ensures teacher and students are correctly assigned.\n\n- 👨🏻‍🎓 **Student Addition and Removal** 👨🏻‍🎓\n  \n  Tests adding/removing students and handles maximum capacity constraints.\n\n- 👩🏻‍🏫 **Teacher Assignment** 👩🏻‍🏫\n  \n  Validates the teacher's assignment and reassignment.\n\n### Mocked Tests\nUses unittest.mock to:\n\n* **Mock Database Calls**: Validates responses from database functions without actual database dependencies.\n\n* **Mock API Calls**: Tests API calls and error handling without hitting real endpoints.\n\n─── ⋆⋅☆⋅⋆ ─────────────────────────────────────────────────────\n\n## 🔎 Sample Code and Fixtures \u003ca id=\"sample-code-and-fixtures\"\u003e\u003c/a\u003e\n- **Fixtures for Reusable Test Objects**: Fixtures in conftest.py help set up reusable test objects for shapes and the classroom environment. One of them is below:\n\n``` python\n# conftest.py\n@pytest.fixture\ndef test_rectangle():\n    return shapes.Rectangle(length=10, width=20)\n```\n\n💡 **Example Test Cases**\n* Testing add function\n``` python\ndef test_add():\n    result = functions.add(number_one=1, number_two=4)\n    assert result == 5\n```\n\n* Testing classroom initialization\n``` python\ndef test_classroom_initialization(hogwarts_classroom):\n    assert hogwarts_classroom.teacher.name == \"Minerva McGonagall\"\n    assert len(hogwarts_classroom.students) == 5\n```\n\n─── ⋆⋅☆⋅⋆ ─────────────────────────────────────────────────────\n\n### 🧩 Notes \u003ca id=\"notes\"\u003e\u003c/a\u003e\n* Skip Tests:\n  Some tests are marked as `@pytest.mark.skip` if a feature is broken or in development.\n\n* Expected Failures:\n  `@pytest.mark.xfail` marks tests that are expected to fail under certain conditions.\n\n\n─── ⋆⋅☆⋅⋆ ─────────────────────────────────────────────────────\n\n## ⚙️ Requirements \u003ca id=\"requirements\"\u003e\u003c/a\u003e\n* Python 3.7+\n* Pytest\n* Mock (for testing API/database dependencies)\n* Requirements specified in `requirements.txt`\n\n─── ⋆⋅☆⋅⋆ ─────────────────────────────────────────────────────\n\n## 🤝 Contributing \u003ca id=\"contributing\"\u003e\u003c/a\u003e\nContributions are welcome! If you would like to contribute to this project, please fork the repository and submit a pull request with your changes.\n\n─── ⋆⋅☆⋅⋆ ─────────────────────────────────────────────────────\n\n## 📜 License \u003ca id=\"license\"\u003e\u003c/a\u003e\nThis project is licensed under the GNU GENERAL PUBLIC LICENSE - see the [LICENSE](https://github.com/kivanc57/pytesting/blob/main/LICENSE) file for details.\n\n─── ⋆⋅☆⋅⋆ ─────────────────────────────────────────────────────\n\n## 📬 Contact \u003ca id=\"contact\"\u003e\u003c/a\u003e\n\nFor any inquiries or contributions, please feel free to reach out.\n- **GitHub Profile**: [kivanc57](https://github.com/kivanc57)\n- **Email**: [kivancgordu@hotmail.com](mailto:kivancgordu@hotmail.com)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkivanc57%2Fpytesting","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkivanc57%2Fpytesting","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkivanc57%2Fpytesting/lists"}