GithubHelp home page GithubHelp logo

janosh / unittest2pytest Goto Github PK

View Code? Open in Web Editor NEW

This project forked from pytest-dev/unittest2pytest

0.0 1.0 0.0 180 KB

helps rewriting Python `unittest` test-cases into `pytest` test-cases

License: GNU General Public License v3.0

Python 100.00%

unittest2pytest's Introduction

unittest2pytest

Helps converting unittest test-cases to pytest

Author

Hartmut Goebel <[email protected]>

Version

0.5.dev0

Copyright

2015-2019 by Hartmut Goebel

Licence

GNU Public Licence v3 or later (GPLv3+)

Homepage

https://github.com/pytest-dev/unittest2pytest

See Build Status on GitHub Actions

unittest2pytest is a tool that helps rewriting Python unittest test-cases into pytest test-cases.

In contrast to other similar tools, this unittest2pytest

  • handles keyword arguments,
  • handles single-line test-cases and several tests on one line,
  • uses context-handlers where appropriate.

This is done by using lib2to3 and Python's mighty inspect module.

Installation

To install unittest2pytest, simply run:

pip install unittest2pytest

Usage

To print a diff of changes that unittest2pytest will make against a particular source file or directory:

unittest2pytest source_folder

To have those changes written to the files:

unittest2pytest -w source_folder

To have those changes written to another directory:

unittest2pytest -w source_folder --output-dir /some/where/else

By default, this will create backup files for each file that will be changed. You can add the -n option to not create the backups. Please do not do this if you are not using a version control system.

For more options about running particular fixers, run unittest2pytest --help or read the lib2to3 documentation. This tool is built on top of that one.

Fixes

A list of the available fixers can be found with the following:

$ unittest2pytest -l
Available transformations for the -f/--fix option:
remove_class
self_assert

Note: if your tests use the context managers with self.assertRaises or with self.assertWarns, they will be transformed to pytest.raises or pytest.warns appropriately, but because the semantics are different, any use of the output value from the context managers (e.g. the x in with pytest.raises(ValueError) as x:) will be wrong and will require manual adjustment after the fact.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.