pytest

py.test with xdist is not executing tests parametrized with random values

我与影子孤独终老i 提交于 2019-12-12 14:45:17
问题 Does anybody noticed the following strange behaviour for pytest and xdist. When trying to run the test that is parametrized with some randomly selected values the test are not actualy run. The same test is executed without any problems if xdist is not used. Following code can be used to reproduce this. import pytest import random PARAMS_NUMBER = 3 PARAMS = [] for i in range(PARAMS_NUMBER): PARAMS.append(random.randrange(0, 1000)) @pytest.mark.parametrize('rand_par', PARAMS) def test_random

py.test -n <number of processes> => “py.test: error: unrecognized arguments: -n”

旧城冷巷雨未停 提交于 2019-12-12 14:24:09
问题 I am trying to distribute django tests to multiple processes to speed up test runs. I am using py.test in a virtual environment. My relevant versions are: $ pip freeze | grep test django-pytest==0.2.0 django-webtest==1.7.7 pytest==2.5.2 pytest-cov==1.6 pytest-django==2.6.2 pytest-xdist==1.10 scripttest==1.3 When I try the command: $ py.test -n 4 I get the error: usage: py.test [options] [file_or_dir] [file_or_dir] [...] py.test: error: unrecognized arguments: -n py.test traceconfig command

Pytest: How to make sure a certain fixture is called first

断了今生、忘了曾经 提交于 2019-12-12 13:47:34
问题 I have some data in a_file which I need to parametrize my fixture with. Therefore, I wrote a helper function which returns a_list filled with the data from the file. Now I can easily parametrize my fixture via @pytest.fixture(params=a_list) . Seems straight forward, right? The problem here is that a_file is generated by another fixture and it seems that pytest calls the helper which relies on that file before the file gets actually created by the fixture. Due to that behavior, a

How to disable multiple plugins in pytest.ini?

試著忘記壹切 提交于 2019-12-12 13:05:44
问题 I have tests within the same repository (separate pytest.ini files) that require different pytest plugins. How can I disable multiple plugins in pytest.ini without uninstalling them? https://docs.pytest.org/en/latest/plugins.html#findpluginname addopts = --nomigrations --reuse-db -s -p no:pytest-splinter works fine, but I also want to disable pytest-django and pytest-bdd for one of the test suites. How can I do that? I've tried: addopts = --nomigrations --reuse-db -s -p no:pytest-splinter -p

pytest cannot find module on import but code runs just fine

谁说胖子不能爱 提交于 2019-12-12 12:26:47
问题 The goal is to use the pytest unit test framework for a Python3 project that uses Cython. This is not a plug-and-play thing, because pytest by default is not able to import the Cython modules. Namely, I get the following error when importing from a Cython .pyx module, in my case named 'calculateScore': package/mainmodule.py:5: in <module> from calculateScore import some_functions E ImportError: No module named 'calculateScore' This problem occurs both when using the pytest-runner as well as

How to print stuff in a py.test finalizer

旧街凉风 提交于 2019-12-12 11:00:56
问题 I'm testing a function that writes to a logfile (it doesn't matter that it writes to a logfile specifically, it could be doing anything, it's just what gave rise to this question) Something like this: def do_stuff(): with open('/tmp/mylogs.txt', 'a') as f: f.write(str(time.time())) f.write(' stuff done! \n') return 42 And I can test it a bit like this: def test_doing_stuff(watch_logs): assert do_stuff() == 42 assert do_stuff() == 43 For debugging purposes, when a test fails, I want to be able

Disable Pytest in PyCharm

余生颓废 提交于 2019-12-12 10:32:51
问题 If I have a file beginning with "test_", PyCharm tries to run this with PyTest. I want to run it normally (as a regular Python script). How can I do this? Edit with Solution: As A. Romeau pointed out, there are ways to do this: For a given test file that you want to run normally: Run the file... note that it runs under py.test or some other testing framework. Click on the drop-down box on the top-right that says something like "py.test in test_something.py". Click "Edit Configurations". This

What does Flaky: Hypothesis test produces unreliable results mean?

余生长醉 提交于 2019-12-12 09:53:11
问题 I am using the hypothesis python package for testing. I am getting the following error: Flaky: Hypothesis test_visiting produces unreliable results: Falsified on the first call but did not on a subsequent one As far as I can tell, the test is working correctly. How do I get around this? 回答1: It means more or less what it says: You have a test which failed the first time but succeeded the second time when rerun with the same example. This could be a Hypothesis bug, but it usually isn't. The

How to get a list of TestReports at the end of a py.test run?

巧了我就是萌 提交于 2019-12-12 09:43:23
问题 I want to get a list of all tests (e.g. in the form of a py.test TestReport) at the end of all tests. I know that pytest_runtest_makereport does something similar, but only for a single test. But I want to implement a hook or something in conftest.py to process the whole list of tests before the py.test application terminates. Is there a way to do this? 回答1: Here an example which can help you. Structure of files: /example: __init__.py # empty file /test_pack_1 __init__.py # empty file

What to do when a py.test hangs silently?

筅森魡賤 提交于 2019-12-12 08:20:36
问题 While using py.test, I have some tests that run fine with SQLite but hang silently when I switch to Postgresql. How would I go about debugging something like that? Is there a "verbose" mode I can run my tests in, or set a breakpoint ? More generally, what is the standard plan of attack when pytest stalls silently? I've tried using the pytest-timeout, and ran the test with $ py.test --timeout=300, but the tests still hang with no activity on the screen whatsoever 回答1: I ran into the same