Skip to main content

PyPI version Supported Python versions Build status Codecov Code coverage

ivoire is an RSpec-like testing framework for Python. It aims to bring a few minor constructs over to Python in a way that isn’t overwhelmingly disruptive or counterculture.

In case you’ve never heard of RSpec, it’s a Ruby BDD framework that is fairly widely used, and whose tests have a style unique from xUnit’s.

Installation

Ivoire is on PyPI and can be installed via pip install ivoire (or via your preferred installation method).

At this point you should consider Ivoire to be experimental, and there are likely plenty of bugs to address, so please file them as you run into them on the issue tracker.

A Small Example

To write specs using Ivoire, simply import and use ivoire.describe. You can then execute the spec using the included ivoire test runner.

Here’s an example of what a specification looks like.

from ivoire import describe, context


class Calculator(object):
    def add(self, x, y):
        return x + y

    def divide(self, x, y):
        return x / y


with describe(Calculator) as it:
    @it.before
    def before(test):
        test.calc = Calculator()

    with it("adds two numbers") as test:
        test.assertEqual(test.calc.add(2, 4), 6)

    with it("multiplies two numbers") as test:
        test.assertEqual(test.calc.multiply(2, 3), 6)

    with context(Calculator.divide):
        with it("divides two numbers") as test:
            test.assertEqual(test.calc.divide(8, 4), 2)

        with it("doesn't divide by zero") as test:
            with test.assertRaises(ZeroDivisionError):
                test.calc.divide(8, 0)

You can find this example at examples/calculator_spec.py, alongside a few others.

After installing Ivoire, running the example above with ivoire examples/calculator_spec.py should produce:

spec output

If you’d like a more verbose output, try passing the -v command line flag.

At some point in the (hopefully very near) future, when I’ve sorted out an import hook, Ivoire will also be able to be run as ivoire transform `which nosetests` --testmatch='(?:^|[\b_\./-])[Ss]pec', which will transform specs automatically into normal unittest.TestCases. Work on this is in progress.

Running the Test Suite

Ivoire’s test suite is currently written mostly in itself, but it still has a small section that is written using the standard unittest test cases.

You can run Ivoire’s test suite by running tox in the root of the repository checkout after installing tox via your package manager or with pip install tox. This will run both parts of the suite.

Contributing

I’m Julian Berman.

You can find me on Freenode in #python-testing and various other channels (nick: tos9) if you’d like to chat.

Ivoire is developed on GitHub.

Feel free to fork and submit patches or feature requests. Your contributions are most welcome!

If you’d like the best chance for them to be merged quickly try to include tests with your pull request, and adhere to general Python coding standards and your own common sense :).

Release files for ivoire 0.4.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ivoire 0.4.0
File Size Uploaded
ivoire-0.4.0.tar.gz 50.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for ivoire 0.4.0
File Interpreter ABI Platform
ivoire-0.4.0-py3-none-any.whl Python 3 none any Details

Total release size: 75.1 kB

Release files / ivoire-0.4.0.tar.gz

Download URL ivoire-0.4.0.tar.gz
Size 50.1 kB
Tags Source
SHA-256 checksum
How to use checksums
88d516595d2740a8f53b1bfed9ff27cce2d59b30f575d1f0a0f5e0801e8c8ff9
BLAKE2b-256 checksum
How to use checksums
badf69f0c63af63511b4e23705d83d8880828ac5951e81c934aae39c3d113d75
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/4.0.2 CPython/3.11.7

Release files / ivoire-0.4.0-py3-none-any.whl

Download URL ivoire-0.4.0-py3-none-any.whl
Size 25.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b34cabcefcc50b7ae36567a4e23a2a4cd05b42110f0649c97f6ae690d699ec98
BLAKE2b-256 checksum
How to use checksums
70ee7434f10d535f3c8c163ad6a1bb7b3c4e38b52fdb15d204ad26c3d2cdab24
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/4.0.2 CPython/3.11.7

Release history Release notifications | RSS feed

This release

0.4.0 This release

2 release files

0.3.2

2 release files

0.3.1

2 release files

0.2

2 release files

0.1

2 release files

0.1dev

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page