pytest

How to run all PyTest tests even if some of them fail?

守給你的承諾、 提交于 2019-12-09 08:59:11
问题 I am looking for a way to run all of my unit tests in PyTest, even if some of them fail. I know there must be a simple way to do this. I checked the CLi options and looked through this site for similar questions/answers but didn't see anything. Sorry if this has already been answered. For example, consider the following code snippet, with PyTest code alongside it: def parrot(i): return i def test_parrot(): assert parrot(0) == 0 assert parrot(1) == 1 assert parrot(2) == 1 assert parrot(2) == 2

How to unit test code that runs celery tasks?

好久不见. 提交于 2019-12-08 18:20:36
问题 The app I am working on is heavily asynchronous. The web application runs a lot of tasks through celery depending on user actions. The celery tasks themselves are capable of launching further tasks. Code such as the one shown below occurs in our code base quite frequently. def do_sth(): logic(); if condition: function1.apply_async(*args) else: function2.apply_asynch(*args) Now we want to start unit testing any new code that we write and we are not sure how to do this. What we would like to

How to run py.test and linters in `python setup.py test`

纵饮孤独 提交于 2019-12-08 17:41:39
问题 I have a project with a setup.py file. I use pytest as the testing framework and I also run various linters on my code ( pep8 , pylint , pydocstyle , pyflakes , etc). I use tox to run these in several Python versions, as well as build documentation using Sphinx . I would like to run my test suites as well as the linters on my source code with the python setup.py test task. If I acheive this, I will then just use python setup.py test as the command for running tests in my tox.ini file. So my

pytest cannot find package when I put tests in a separate directory

余生长醉 提交于 2019-12-08 16:31:21
问题 I have a very basic example of a Python package and a test which I'm trying to run with pytest package \-- __init__.py spam.py spam_test.py __init__.py is empty, spam.py defines a single function func() and spam_test.py is: import package.spam def test_func(): assert(package.spam.func() == 5) In the root directory I run py.test and it all works, returning one passing test. I thought that I could also structure things in this way: package \-- __init__.py spam.py tests \-- spam_test.py But now

Returning multiple objects from a pytest fixture

柔情痞子 提交于 2019-12-08 15:04:37
问题 I am learning how to use pytest by testing a simple event emitter implementation. Basically, it looks like this class EventEmitter(): def __init__(self): ... def subscribe(self, event_map): # adds listeners to provided in event_map events def emit(self, event, *args): # emits event with given args For convenience, I created a Listener class that is used in tests class Listener(): def __init__(self): ... def operation(self): # actual listener Currently, test looks the following way @pytest

simplest way of parameterizing tests in python?

混江龙づ霸主 提交于 2019-12-08 11:02:25
问题 I have a library with a bunch of different objects that have similar expected behavior, thus I want to run similar tests on them, but not necessarily identical tests on them. To be specific lets say I have some sorting functions, and a test for checking if a sorting function actually sorts. Some sorting functions are intended to work on some inputs, but not others. I'd like to write something close to the code below. However, nose won't do a good job of telling me exactly where the tests

on MAC OS X, py.test not recognized as a command

為{幸葍}努か 提交于 2019-12-08 05:37:47
问题 On MAC OS X 10.10; I installed pytest 2.6.4; however in Terminal If I write py.test or even py.test --version; I get the error: -bash: py.test command not found (a) Am I missing anything? What do I do to make the pytest tool recognizable. I searched alot; but couldn't find any info except http://teckla.idyll.org/~t/transfer/py.test.html I checked in the PyCharm preferences, I don't see py.test interpreter listed there. However, pip freeze displays pytest 2.6.4 installed. (b) Is PYTHONPATH

Need py.test to log assert errors in log file from python logging module

别等时光非礼了梦想. 提交于 2019-12-08 05:11:29
问题 Need py.test to log assert errors in log file from python logging module. The test has python logging module set up and all logs goes there as expected. I used assert statements through out the test. But when encounter assertion errors, those messages are not logged in the python logging output but in command console. Is there a way to get py.test to log the assertion errors in the test's logging output? Right now the errors are in command console but it would be great if these assertion

pytest configuration problem (transition from nosetests (71 sec) to pytest (1536 sec))

不羁岁月 提交于 2019-12-08 05:09:41
问题 The problem: pytest (decided by policy) takes 1536 seconds to run the same test suite (585 tests) as nosetest , which runs in 71 seconds. The pytest.ini files is: [pytest] python_files = tests_*.py *_tests.py norecursedirs = .idea (pycharm env). testpaths = tests And the file is placed at the root of the project: root |-+ mod1 | |-- core.py | |-- utils.py |-+ mod2 | |-- core.py | |-- utils2.py |-+ tests | |-- test_mod1 | |-- test_mod2 |-+ utils (don't test). | |-- u1.py | |-- u2.py |- pytest

Skipping pytest unless a parameter is present

左心房为你撑大大i 提交于 2019-12-07 20:05:22
问题 I want to use unittest.skiptest but only skip a test if a parameter is given at command line. This lets me do integration tests easier. How can I do this? 回答1: The documentation is filled with helpful information. You'll find what you are looking for here. No need to use skiptest at all. Basically, just use the conftest.py file to define a new command line option and then go about marking the tests with your new annotation. Note: The annotation and parameter can be different.. 回答2: You can