Test-driven source code search for Python.
Project description
pytest-nodev is a simple test-driven search engine for live code, it finds classes and functions matching the behaviour specified by the given tests.
Development status: beta.
New user FAQ
What is pytest-nodev?
To be more precise pytest-nodev is a pytest plugin that helps you execute specification tests on all objects in the Python standard library and in all the modules you have installed.
Who are pytest-nodev users?
Python developers who’ve got better things to do than reinvent wheels.
Sounds interesting, I need a function that robustly parses a boolean value from a string. Here’s my specification test:
def test_parse_bool(): assert not parse_bool('false') assert not parse_bool('FALSE') assert not parse_bool('0') assert parse_bool('true') assert parse_bool('TRUE') assert parse_bool('1')
Show me how searching with pytest-nodev work.
First, install the latest version of pytest-nodev from the Python Package Index:
$ pip install pytest-nodev
Then copy your specification test to the test_parse_bool.py file and instrument it with the wish fixture:
def test_parse_bool(wish): parse_bool = wish assert not parse_bool('false') assert not parse_bool('FALSE') assert not parse_bool('0') assert parse_bool('true') assert parse_bool('TRUE') assert parse_bool('1')
Finally, instruct pytest-nodev to run your test on all functions in the Python standard library:
$ py.test test_parse_bool.py --wish-from-stdlib ======================= test session starts ========================== platform darwin -- Python 3.5.0, pytest-2.8.7, py-1.4.31, pluggy-0.3.1 rootdir: /tmp, inifile: setup.cfg plugins: nodev-1.0.0, timeout-1.0.0 collected 3259 items test_parse_bool.py xxxxxxxxxxxx[...]xxxxxxxxXxxxxxxxx[...]xxxxxxxxxxxx ============================== 1 hit ================================= test_parse_bool.py::test_parse_bool[distutils.util:strtobool] HIT ==== 3258 xfailed, 1 xpassed, 27 pytest-warnings in 45.07 seconds ====
In less than a minute pytest-nodev collected more than 3000 functions from the standard library and run your specification test on all of them and you’ve got a HIT. The strtobool function in the distutils.util module passes the test, so now you should thoroughly review it and if you like it you may use it in your code, no need to write your own implementation.
Wow! Does it work so well all the times?
To be honest strtobool is a little known gem of the Python standard library that is just perfect for illustrating all the benefits of the search-by-tests strategy. Here are some of them in rough order of importance:
a function imported is a one less function coded—and tested, documented, debugged, ported, maintained…
it’s battle tested code—lot’s of old bugs have already been squashed
it’s other people code—there’s an upstream to report new bugs to
it gives you additional useful functionality—for free on top of that
it’s in the Python standard library—no additional dependency required
BIG FAT WARNING!
A lot of functions called with the wrong set of arguments may have unexpected consequences ranging from slightly annoying, think os.mkdir('false'), to utterly catastrophic, think shutil.rmtree('/', True). Serious use of pytest-nodev, in particular using --wish-from-all, require operating-system level isolation, e.g. a dedicated user or even better a dedicated container.
Discussion on how to best help users sandboxing pytest-nodev is ongoing, see issue #16.
Project resources
Documentation |
|
Support |
|
Development |
|
Discussion |
To be decided, see issue #15 |
Download |
|
Code quality |
|
nodev website |
Contributing
Contributions are very welcome. Please see the CONTRIBUTING document for the best way to help. If you encounter any problems, please file an issue along with a detailed description.
Authors:
Alessandro Amici - @alexamici
Contributors:
Sponsors:
License
pytest-nodev is free and open source software distributed under the terms of the MIT license.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file pytest-nodev-0.9.5.tar.gz
.
File metadata
- Download URL: pytest-nodev-0.9.5.tar.gz
- Upload date:
- Size: 22.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f146ab5093c387ff9609fcfa12a8aaa2593a5efcdfed5ab892ada40d032235f7 |
|
MD5 | 62c6a8c30de5c9061485db9787b1fa3d |
|
BLAKE2b-256 | 93bb346c1aef0e971057c4affa9313eb455d8d53d1c2742c9e8be7d9a91d0834 |
File details
Details for the file pytest_nodev-0.9.5-py2.py3-none-any.whl
.
File metadata
- Download URL: pytest_nodev-0.9.5-py2.py3-none-any.whl
- Upload date:
- Size: 15.6 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a917459c32bb14598ffc15fb1dd4acd4fb3831cc2f1c73a69b7f6308175fa282 |
|
MD5 | 389e6691c6c2cd23243e358c5d697e84 |
|
BLAKE2b-256 | d8872c1ac87906ddf3a47648c66154a31e84326acee5df06dba9eefe32cacd63 |