Hi,
opening a ticket because I couldn't figure this out from the documentation? Can Pytest be used to test Python scripts instead of Python modules?
Thorsten
its not clear what you man by "testing scripts"
you could just run py.test myscript.py and include unittests inside the script itself, or do any kind of tenting the usual way (just make the script importable and call into it)
as for testing a script in general, thats a language agnostig problem
usually "python scripts" these days should not be written, and instead a module with a console_scripts entrypoint should be done (eases pypi distribution and windows support)
pytest is just a test runner. If your test executes the command line or terminal applications then you can invoke them using subprocess or similar and use the output capturing to check results. There might be a plugin which helps this scenario even further but I can't remember that on top of my head.
I have a Python script
#! /usr/bin/env python
print('Hello, World!')
I would like to ensure via Pytest that it really prints Hello, World! to stdout and returns without error. Is that possible with Pytest?
yes, by running subprocess.statusoutput and asserting on the result
your problem is generic script testing, so the test framework doesn't matter, all you need to do is invoke a process and take a look at the output
there are various libraries that help with it
@kvas-it is/was developing pytest-console-scripts just with that purpose in mind. 😁
Yes, indeed I started that plugin exactly for this. Perhaps I should get my act together, figure out why the travis build breaks and publish this on pypi. Right now not sure when it will be done but thanks for some motivation ;)
Closing this for now, feel free to reopen if you have further questions @thorstenkampe.
Just FYI, pytest-console-scripts is now published on pypi and is basically usable.
Very nice Vasily!
On Mon, Nov 14, 2016, 14:47 Vasily Kuznetsov [email protected]
wrote:
Just FYI, pytest-console-scripts
https://github.com/kvas-it/pytest-console-scripts is now published on
pypi and is basically usable.—
You are receiving this because you modified the open/close state.Reply to this email directly, view it on GitHub
https://github.com/pytest-dev/pytest/issues/1956#issuecomment-260390151,
or mute the thread
https://github.com/notifications/unsubscribe-auth/ABCO_BgJ-le8tuu6kr9CSv9es2g9eVZRks5q-JClgaJpZM4KDrR4
.
Most helpful comment
Just FYI, pytest-console-scripts is now published on pypi and is basically usable.