
Security News
Browserslist-rs Gets Major Refactor, Cutting Binary Size by Over 1MB
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.
microPyTest is a minimal, pure python-based test runner that you can use directly in code.
micropytest
command, but embedding in your own code is the primary focus.Install directly from PyPI:
pip install micropytest
Suppose you have some test files under my_tests/
:
# my_tests/test_example.py
def test_basic():
assert 1 + 1 == 2
def test_with_context(ctx):
ctx.debug("Starting test_with_context")
assert 2 + 2 == 4
ctx.add_artifact("numbers", {"lhs": 2, "rhs": 2})
You can run them from a Python script:
import micropytest.core
results = micropytest.core.run_tests(tests_path="my_tests")
passed = sum(r.status == "pass" for r in results)
total = len(results)
print(f"Test run complete: {passed}/{total} passed")
ctx
parameter gets a TestContext object with .debug()
, .warn()
, .add_artifact()
, etc.microPyTest includes a Command
class for running and interacting with external processes:
from micropytest.command import Command
import sys
def test_interactive_command(ctx):
# Run a Python interpreter interactively
with Command([sys.executable, "-i"]) as cmd:
# Send a command
cmd.write("print('Hello, world!')\n")
# Check the output
stdout = cmd.get_stdout()
# Exit the interpreter
cmd.write("exit()\n")
# Verify the output
assert any("Hello, world!" in line for line in cmd.get_stdout())
Key features:
You can run a subset of tests by specifying a filter pattern:
# Run only tests with "artifact" in their name
results = micropytest.core.run_tests(tests_path="my_tests", test_filter="artifact")
This is especially useful when you're focusing on a specific area of your codebase.
Tests can accept and parse command-line arguments using standard Python's argparse
:
def test_with_args(ctx):
import argparse
# Create parser
parser = argparse.ArgumentParser(description="Test with arguments")
parser.add_argument("--string", "-s", default="default string", help="Input string")
parser.add_argument("--number", "-n", type=int, default=0, help="Input number")
# Parse arguments (ignoring unknown args)
args, _ = parser.parse_known_args()
# Log the parsed arguments
ctx.debug(f"Parsed arguments:")
for key, value in vars(args).items():
ctx.debug(f" {key}: {value}")
# Use the arguments in your test
assert args.string != "", "String should not be empty"
assert args.number >= 0, "Number should be non-negative"
When running from the command line, you can pass these arguments directly:
micropytest --test test_with_args --string="Hello World" --number=42
The arguments after your test filter will be passed to your test functions, allowing for flexible test parameterization.
Code-first: You typically call run_tests(...)
from Python scripts. The CLI is optional if you prefer it.
Artifact handling is built-in: ctx.add_artifact("some_key", value)
can store data for later review. No extra plugin required.
Command execution built-in: No need for external plugins to run and interact with processes.
No fixtures or plugins: microPyTest is intentionally minimal. Tests can still share state by passing a custom context class if needed.
No configuration: There's no pytest.ini
or conftest.py
. Just put your test functions in test_*.py
or *_test.py
.
Time estimates for each test
See the examples subfolder
If you prefer a command-line flow:
micropytest -p tests/
--verbose
: Show all debug logs & artifacts.--quiet
: Only prints a final summary.--test
: Run only tests matching the specified pattern.--dry-run
: Show what tests would be run without actually running them (will assume them to pass).Examples:
# Run all tests in my_tests directory
micropytest -v my_tests
# Run only tests with "artifact" in their name
micropytest -t artifact my_tests
# Run a specific test and pass arguments to it
micropytest -t test_cmdline_parser --string="Hello" --number=42
To develop with microPyTest, install the required dependencies and run the tests in the project:
pip install rich
python -m micropytest .
To build and upload a new version to PyPI:
# Install build tools
pip install build twine
# Build the distribution packages
python -m build
# Upload to PyPI
python -m twine upload dist/micropytest-xxx.tar.gz
Make sure to update the version number in __init__.py
and pyproject.toml
before building a new release.
Enjoy your micro yet mighty test runner!
FAQs
A micro test runner
We found that micropytest demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.
Research
Security News
Eight new malicious Firefox extensions impersonate games, steal OAuth tokens, hijack sessions, and exploit browser permissions to spy on users.
Security News
The official Go SDK for the Model Context Protocol is in development, with a stable, production-ready release expected by August 2025.