pytest

Django channels 2, accessing db in tests

▼魔方 西西 提交于 2019-12-14 01:43:40
问题 I recently updated my project to Django 2 and channels 2. Right now I am trying to rewrite my tests for chat app. I am facing a problem with tests that depend on django db mark from pytest-django. I tried to create objects in fixtures, setup methods, in test function itself, using async_to_sync on WebsocketCommunicator . However, none of those worked. If I create a user in a fixture and save it correctly gets an id. However, in my consumer Django does not see that User in the database. And

My Travis keeps erroring

一世执手 提交于 2019-12-13 20:40:38
问题 All tests are passing, but in in the end, it gives The command "make html" failed and exited with 2 during . This happens since I started using cache. Initially I just had cache: apt: true directories: - $HOME/virtualenv/python2.7/lib/python2.7/site-packages - node_modules in travis.yml but I also added - $HOME/virtualenv/bin and cleared my cache in master branch before I ran another build. It passed once, but then keeps failing. I cleared the cache multiple times but no avail. 来源: https:/

when running Pytest test through ssh I get “no module named pandas” although module is installed

最后都变了- 提交于 2019-12-13 20:27:01
问题 when running Pytest test through ssh I get " no module named pandas " although module is installed both on vritual environment and locally. Can somebody point out where else should I install it? I access my server: ssh user@server.com enter password run the following command: " py.test -s -v jupyter_test.py ". It runs tests, and as test result I get above mentioned error. When I do test on server, without ssh , it works perfectly. But I need to do it through ssh. 回答1: the reason was that on

How to let pytest hooks print to the console?

一个人想着一个人 提交于 2019-12-13 19:51:03
问题 I know about pytest -s . However, I would like to let a hook print to the console. The following didn't work for me: terminal_reporter = request.config.pluginmanager.getplugin("terminalreporter") terminal_reporter.write_line("TEST") This still needed pytest -s to run. Instead I'd like to circumvent that. Specifically, I'm overwriting the pytest_bdd_before_scenario() hook to print the steps that are being executed. 回答1: For the hooks that are not involved in test execution (configuration,

pytest parameterized method setup

萝らか妹 提交于 2019-12-13 07:19:17
问题 I have a parameterized pytest test method, test_1 . Before all the parameterized cases are run for this test method, I'd like to call another method, tmp_db_uri , which creates a temporary database and yields the uri for the database. I only want to call that generator once, so that I can use the same temporary database for all the test cases. I thought that if I called it from a fixture ( db_uri ), that would do the trick, since I thought that fixtures are created once per test, but it seems

pytest run tests inside a class with a constructor

空扰寡人 提交于 2019-12-13 07:16:57
问题 I want to write a test suite for an API. my project tree looks like: project tree I need to have a 'client' file with classes where we initialize all the helper functions(e.g. the actual request that is sent with the params, asserts, configs etc.). And the actual test class. so I have class Client() __init__() def helper_function() class TestBackend(Client) __init__() def test_something() Then I try to run my tests with pytest. I keep getting PytestWarning: cannot collect test class

Not able to generate allure report in pytest. Getting 'AttributeError: module 'allure' has no attribute 'severity_level''

倾然丶 夕夏残阳落幕 提交于 2019-12-13 03:59:18
问题 I have 2 files- conftest.py: import pytest from selenium import webdriver driver = None @pytest.fixture(autouse = True) def browserSetAndClose(): global driver EXE_PATH = r'C:\Users\1602746\Softwares\chromedriver.exe' chromeOptions = webdriver.ChromeOptions() chromeOptions.add_experimental_option('useAutomationExtension', False) driver = webdriver.Chrome(executable_path = EXE_PATH, options = chromeOptions, desired_capabilities = chromeOptions.to_capabilities()) driver.implicitly_wait(10)

How can I remove “@oidc.login_required” for unit testing from a view?

北慕城南 提交于 2019-12-13 03:26:50
问题 I use flask-oidc for user login and pytest for testing. For unit testing, I would like to "remove" @oidc.require_login . How can I do that? What I tried The way flask-o works is roughly: from flask import Flask, url_for, redirect from flask_oidc import OpenIDConnect app = Flask(__name__) app.config['OIDC_CLIENT_SECRETS'] = 'client_secrets.json' # Contents: # Create client_id and client_secret at https://console.developers.google.com/apis/credentials # { # "web": { # "client_id": "123456789012

pytest not discovering test in pyDev

风流意气都作罢 提交于 2019-12-13 02:57:19
问题 I'm trying to build and run (selenium which is not relevant) test-suite with pytest framework. I wrote a simple test as follows class test_pqr(): def test_lmn(self): print("AAAAAAAAAAAAAAAAAAAAA") assert True def test_xyz(self): assert False x= test_pqr() x.test_lmn() when I run it I got result... if I run xyz as well... eg class test_pqr(): def test_lmn(self): print("AAAAAAAAAAAAAAAAAAAAA") assert True def test_xyz(self): assert False x= test_pqr() x.test_lmn() x.test_xyz() get results as...

pytest - test flow order

女生的网名这么多〃 提交于 2019-12-13 02:27:51
问题 I have a pytest code similar to below... if i run it with --count 3 it will run the test_first 3 times then test_second 3 times. What if i would like it to run test_first, test_second and repeat that flow? Thanks.:) @pytest.mark.usefixtures('setup') class TestSomething: def run_setup(self): pass def test_first(self): print('test 1') name = 'name' assert name.isalpha() def test_second(self): print('test 2') name = '12345' assert name.isalpha() 回答1: You can implement it yourself. Take a look at