🌐
GitHub
github.com › samuel-lab › Python-Code-Tester
GitHub - samuel-lab/Python-Code-Tester
Contribute to samuel-lab/Python-Code-Tester development by creating an account on GitHub.
Author   samuel-lab
🌐
GitHub
docs.github.com › en › actions › tutorials › build-and-test-code › python
Building and testing Python - GitHub Docs
... steps: - uses: actions/checkout@v5 ... -r requirements.txt - name: Test with pytest run: | pip install pytest pytest-cov pytest tests.py --doctest-modules --junitxml=junit/test-results.xml --cov=com --cov-report=xml ...
Discussions

How do people test their codes?
There are multiple ways: Ideally, your code should be made up of narrow-purpose functions that take arguments and returns data. When your code is set up like that, you can just open a REPL/Python Console, and "throw data" at the function to see what it does. Also once your code is broken up into functions, you can just write unit tests to run assertions against the code. This has the benefit of being re-usable in the future. Regarding "I dont want to input codes that might need to be removed or ruins my original code.", this is a good use-case for version control. Commit the version of the code, mess with it by adding stuff, then just revert the changes when you're done. More on reddit.com
🌐 r/learnpython
43
30
November 19, 2023
Malicious little project: Python DDOS tester
Looks interesting, but why are you using a full browser for each request? If you want to make a "load tester" (not a ddos tester!) then you want to generate as much load as possible, which means the highest number of requests per second. The overhead of a browser is simply going to destroy any hope you have of a large number of requests a second, so I would advise using something like requests or plain urllib. If you really really want to be hardcore then a simple asyncio script will be able to get the highest number of requests a second (much higher than threads), but it will require a bit more code modifications than just plain requests/urllib. tl;dr this code is better if you actually want to test the load: import requests while True: requests.get("http://somesite.com/", proxy={"http": "http://some-proxy:1337"}) More on reddit.com
🌐 r/Python
9
5
May 16, 2016
Is there a way to test GitHub actions YAML code locally?
https://github.com/nektos/act I have used this tool in the past, but honestly, I have found it better to make your GitHub action as simple as possible. I do this by writing scripts to do the heavy lifting for an "action" and then simply have your action call the script. This accomplishes a number of things I want to do. 1) I have a script that is testable. 2) IF I ever move away from GitHub or change where I run my CI/CD pipeline. I don't have to redo everything. I simply just put together the new process's version of a GitHub Action to just call the script. More on reddit.com
🌐 r/github
8
14
July 11, 2023
New to Python code testing. What frameworks/references/etc. would you suggest I check out?

Honestly, it sounds like you already have a pretty good handle on tutorials and instructional material, as well as the landscape of options.

I think you will find pytest easy, flexible, and powerful, if you have time to try it out. More importantly, Brian Okken is considering making pytest refrigerator magnets. So that is something.

I like pytest not just for the tool, but for the plugin ecosystem.

More on reddit.com
🌐 r/learnpython
17
210
September 30, 2020
🌐
GitHub
github.com › CleanCut › green
GitHub - CleanCut/green: Green is a clean, colorful, fast python test runner. · GitHub
Green is a clean, colorful, fast python test runner. - CleanCut/green
Starred by 806 users
Forked by 74 users
Languages   Python 97.3% | Shell 1.4% | Makefile 1.3%
🌐
RTavenar
rtavenar.github.io › poly_python › content › test.html
Tester son code — Introduction à Python
Il existe en Python des outils dédiés au test de programmes. Toutefois, ce chapitre ne traite pas de l’utilisation de ces outils, mais plutôt de l’intérêt des tests en général. Dans ce document, nous avons jusqu’à présent supposé que tout se passait bien, que votre code ne ...
🌐
GitHub
github.com › AutomationPanda › python-testing-101
GitHub - AutomationPanda/python-testing-101: Example projects for the Python Testing 101 series from Automation Panda
This repository contains example projects for the Python Testing 101 series from Automation Panda. Each folder in this repository is a separate example project.
Starred by 72 users
Forked by 98 users
Languages   Python 100.0% | Python 100.0%
🌐
GitHub
github.com › pytest-dev › pytest
GitHub - pytest-dev/pytest: The pytest framework makes it easy to write small tests, yet scales to support complex functional testing · GitHub
The pytest framework makes it easy to write small tests, yet scales to support complex functional testing - pytest-dev/pytest
Starred by 13.7K users
Forked by 3.1K users
Languages   Python
🌐
GitHub
github.com › cleder › awesome-python-testing
GitHub - cleder/awesome-python-testing: Collection of awesome 😎️ Python resources for testing
Collection of awesome Python resources for testing and generating test data. ... easycheck - A collection of assertion-like functions to be used in code, where assertion themselves should be avoided; easycheck includes also function aliases ...
Starred by 276 users
Forked by 34 users
Find elsewhere
🌐
GitHub
github.com › topics › python-testing
python-testing · GitHub Topics · GitHub
This project is a quick review on testing in python. It provides a set of tools and frameworks to help you write, automate, and run tests for your Python code
🌐
GitHub
github.com › PyCQA › pycodestyle
GitHub - PyCQA/pycodestyle: Simple Python style checker in one Python file · GitHub
Simple Python style checker in one Python file. Contribute to PyCQA/pycodestyle development by creating an account on GitHub.
Starred by 5.2K users
Forked by 752 users
Languages   Python 99.9% | Makefile 0.1%
🌐
GitHub
docs.github.com › en › actions › tutorials › build-and-test-code
Building and testing your code - GitHub Docs
Learn how to create a continuous integration (CI) workflow to build and test your Python project.
🌐
Menziess
menziess.github.io › howto › test › python-code
Test Python Code - menziess blog
Create a python file called test_main.py to the tests/demo/ folder that contains the following code:
🌐
GitHub
github.com › topics › python-tests
python-tests · GitHub Topics · GitHub
A Rest-API test automation framework which is build on the top of Python language using PyTest Framework.
🌐
Reddit
reddit.com › r/learnpython › how do people test their codes?
r/learnpython on Reddit: How do people test their codes?
November 19, 2023 -

I have my main program and sometimes i get stuck and i want to “test” out random things here and there. I dont want to input codes that might need to be removed or ruins my original code.

How do you guys go about testing new codes? Do you simply copy the entire program into another file or copy on sections?

Just seeing what is the best practice.

Top answer
1 of 15
37
There are multiple ways: Ideally, your code should be made up of narrow-purpose functions that take arguments and returns data. When your code is set up like that, you can just open a REPL/Python Console, and "throw data" at the function to see what it does. Also once your code is broken up into functions, you can just write unit tests to run assertions against the code. This has the benefit of being re-usable in the future. Regarding "I dont want to input codes that might need to be removed or ruins my original code.", this is a good use-case for version control. Commit the version of the code, mess with it by adding stuff, then just revert the changes when you're done.
2 of 15
29
You got a lot of good advice but no examples, so here's one for you. This is a simple program that calculates change in American coins. # Calculate the number of coins needed to make change for a given amount of money # Get input from user total = int(input("Enter amount of money in cents: ")) if total <= 0: print('no change') else: # calculate the number of coins num_dollars = total // 100 total %= 100 num_quarters = total // 25 total %= 25 num_dimes = total // 10 total %= 10 num_nickels = total // 5 total %= 5 num_pennies = total # print output print("Your change is:") print(f"{num_dollars} dollars") print(f"{num_quarters} quarters") print(f"{num_dimes} dimes") print(f"{num_nickels} nickels") print(f"{num_pennies} pennies") Most new programmers have code that looks like this. It's all in one file with no functions. Test it by running the program and typing 366. You should get the following output: Enter amount of money in cents: 366 Your change is: 3 dollars 2 quarters 1 dimes 1 nickels 1 pennies The problem is that this is not very testable, for several reasons: Everytime you run it, you have to MANUALLY input a test number. It would be much better if you could just type up a few tests and have it check the same tests every time you change something. You can't import this into another python file, cause it'll run all the code. You have manually LOOK with your eyes at the output to see if it's right. It would be nicer if the computer could just check itself without you. So the very first thing you have to do, before you're able to test, is to REFACTOR the code into something that's more testable. Separate the input from the calculations from the output. And make it importable by "hiding" it all behind a main() function. That might look something like this (exact_change.py): #!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Calculate the number of coins needed to make change for a given amount of money """ def get_input(): ''' Get input from user ''' return int(input("Enter amount of money in cents: ")) def calculate_coins(total): ''' Calculate the number of coins needed to make change''' num_dollars = total // 100 total %= 100 num_quarters = total // 25 total %= 25 num_dimes = total // 10 total %= 10 num_nickels = total // 5 total %= 5 num_pennies = total return num_dollars, num_quarters, num_dimes, num_nickels, num_pennies def print_coins(num_dollars, num_quarters, num_dimes, num_nickels, num_pennies): ''' Print the number of coins needed to make change for a given amount of money ''' print("Your change is:") print(f"{num_dollars} dollars") print(f"{num_quarters} quarters") print(f"{num_dimes} dimes") print(f"{num_nickels} nickels") print(f"{num_pennies} pennies") def main(): total = get_input() if total <= 0: print('no change') else: num_dollars, num_quarters, num_dimes, num_nickels, num_pennies = calculate_coins(total) print_coins(num_dollars, num_quarters, num_dimes, num_nickels, num_pennies) if __name__ == '__main__': main() Now the code is separated into different parts and "hidden" behind the if __name__ == '__main__':, which means you can import it safely. You can test the calculation part separately by just calling calculate_coins(total) and seeing what it returns. So in a SEPARATE file (test_exact_change.py), you can do something like this: #!/usr/bin/env python3 # -*- coding: utf-8 -*- import unittest import exact_change class TestExactChange(unittest.TestCase): ''' Test the exact_change.py program ''' def test_calculate_coins(self): ''' Test the calculate_coins function ''' self.assertEqual(exact_change.calculate_coins(0), (0, 0, 0, 0, 0)) self.assertEqual(exact_change.calculate_coins(1), (0, 0, 0, 0, 1)) self.assertEqual(exact_change.calculate_coins(4), (0, 0, 0, 0, 4)) self.assertEqual(exact_change.calculate_coins(5), (0, 0, 0, 1, 0)) self.assertEqual(exact_change.calculate_coins(9), (0, 0, 0, 1, 4)) self.assertEqual(exact_change.calculate_coins(10), (0, 0, 1, 0, 0)) self.assertEqual(exact_change.calculate_coins(24), (0, 0, 2, 0, 4)) self.assertEqual(exact_change.calculate_coins(25), (0, 1, 0, 0, 0)) self.assertEqual(exact_change.calculate_coins(49), (0, 1, 2, 0, 4)) self.assertEqual(exact_change.calculate_coins(50), (0, 2, 0, 0, 0)) self.assertEqual(exact_change.calculate_coins(99), (0, 3, 2, 0, 4)) self.assertEqual(exact_change.calculate_coins(100), (1, 0, 0, 0, 0)) self.assertEqual(exact_change.calculate_coins(199), (1, 3, 2, 0, 4)) self.assertEqual(exact_change.calculate_coins(200), (2, 0, 0, 0, 0)) self.assertEqual(exact_change.calculate_coins(366), (3, 2, 1, 1, 1)) self.assertEqual(exact_change.calculate_coins(499), (4, 3, 2, 0, 4)) self.assertEqual(exact_change.calculate_coins(500), (5, 0, 0, 0, 0)) self.assertEqual(exact_change.calculate_coins(999), (9, 3, 2, 0, 4)) self.assertEqual(exact_change.calculate_coins(1000), (10, 0, 0, 0, 0)) if __name__ == '__main__': unittest.main() WHOA! That's a lot of tests! But the fun part is you only have to write them once. Now everytime you run this file - python test_exact_change.py, it will run all those tests, typically in about a millisecond, and tell you if anything is wrong. Rad. That's way faster than doing it manually, and much less chances of making a mistake, too. Hope this helps.
🌐
GitHub
github.com › sousampere › python_module_00_tester
GitHub - sousampere/python_module_00_tester: Tester for 42 students to test their python_module_00
Tester for 42 students to test their python_module_00 - sousampere/python_module_00_tester
Author   sousampere
🌐
GitHub
github.com › se2p › pynguin
GitHub - se2p/pynguin: The PYthoN General UnIt Test geNerator is a test-generation tool for Python
The PYthoN General UnIt Test geNerator is a test-generation tool for Python - se2p/pynguin
Starred by 1.4K users
Forked by 96 users
Languages   Python 99.4% | Python 99.4%
🌐
ExtendsClass
extendsclass.com › python.html
Python tester - Test code online
Python tester allows to test Python code Online without install, all you need is a browser.
🌐
Snyk
snyk.io › code-checker › python
Python AI-powered Code Checker | Powered By Snyk Code | Snyk
This approach strengthens both the quality and security of Python code over time, fostering a higher standard of software development. By promoting maintainable code and reducing defects and technical debt, organizations can deliver more reliable applications and ultimately enhance the overall user experience. with static application security testing built by, and for, developers. Start free with GitHubStart free with Google ·
🌐
GitHub
github.com › PyCQA
Python Code Quality Authority · GitHub
July 7, 2019 - Organization for code quality tools (and plugins) for the Python programming language - Python Code Quality Authority
🌐
GitHub
github.com › testing-cabal › mock
GitHub - testing-cabal/mock: The Python mock library
The Python mock library. Contribute to testing-cabal/mock development by creating an account on GitHub.
Starred by 538 users
Forked by 104 users
Languages   Python 100.0% | Python 100.0%