pytest

None response and empty title from selenium webdriver in functional test

非 Y 不嫁゛ 提交于 2020-07-10 10:26:28
问题 I followed this tutorial (Build DevOps CI/CD pipeline for Python Flask with Azure DevOps). There is a command line task to execute a functional test which I get an error while running it. The command line task script is as follows: pip install selenium && pip install pytest && pytest Tests/functional_tests/ --webAppUrl=$(webAppUrl.AppServiceApplicationUrl) --junitxml=TestResults/test-results.xml This is the script used for functional test: import pytest from selenium import webdriver import

None response and empty title from selenium webdriver in functional test

荒凉一梦 提交于 2020-07-10 10:26:02
问题 I followed this tutorial (Build DevOps CI/CD pipeline for Python Flask with Azure DevOps). There is a command line task to execute a functional test which I get an error while running it. The command line task script is as follows: pip install selenium && pip install pytest && pytest Tests/functional_tests/ --webAppUrl=$(webAppUrl.AppServiceApplicationUrl) --junitxml=TestResults/test-results.xml This is the script used for functional test: import pytest from selenium import webdriver import

how to avoid decorators while unit testing in python flask application

旧时模样 提交于 2020-07-09 05:18:06
问题 I am new to python and flask. I wanted to create unit tests for an api written. We have used jwt for authentication. To unit test, I don't want the flow to enter @jwt_required decorator. In addition to that I have chained a few other decorators for that method. class A(): @jwt_required() @mandatory_fields_check @unlock_and_lock() def get(self, address, name): .. .. .. return jsonify( {"payload": data, "message": "data received successfully"}), 200 Unit test I am trying to write def test_get()

Replacement for test case inheritance in pytest?

ぃ、小莉子 提交于 2020-07-08 21:31:49
问题 Background In Python's unittest framework, it is a fairly common idiom to use inheritance on a base set of tests to apply an entire set of tests to a new problem, and occasionally to add additional tests. A trivial example would be: from unittest import TestCase class BaseTestCase(TestCase): VAR = 3 def test_var_positive(self): self.assertGreaterEqual(self.VAR, 0) class SubTestCase(BaseTestCase): VAR = 8 def test_var_even(self): self.assertTrue(self.VAR % 2 == 0) Which, when run, runs 3 tests

Replacement for test case inheritance in pytest?

假装没事ソ 提交于 2020-07-08 21:29:35
问题 Background In Python's unittest framework, it is a fairly common idiom to use inheritance on a base set of tests to apply an entire set of tests to a new problem, and occasionally to add additional tests. A trivial example would be: from unittest import TestCase class BaseTestCase(TestCase): VAR = 3 def test_var_positive(self): self.assertGreaterEqual(self.VAR, 0) class SubTestCase(BaseTestCase): VAR = 8 def test_var_even(self): self.assertTrue(self.VAR % 2 == 0) Which, when run, runs 3 tests

Fixing 'Import [module] could not be resolved' in pyright

早过忘川 提交于 2020-07-07 09:41:11
问题 I'm using pyright for type checking and I'm also using pytest for testing inside Visual Studio Code. The folder structure for my tests is to have a 'test' subfolder in the package root . For example | MyPackage |-- __init__.py |-- MyModule.py |--test |-- __init__.py |--MyModule_test.py I'm organizing things like this as there will be many packages and I want to keep things organized. Inside pytest I have import pytest import MyPackage.MyModule ... Pytest is able to discover the tests and run

Fixing 'Import [module] could not be resolved' in pyright

心已入冬 提交于 2020-07-07 09:36:55
问题 I'm using pyright for type checking and I'm also using pytest for testing inside Visual Studio Code. The folder structure for my tests is to have a 'test' subfolder in the package root . For example | MyPackage |-- __init__.py |-- MyModule.py |--test |-- __init__.py |--MyModule_test.py I'm organizing things like this as there will be many packages and I want to keep things organized. Inside pytest I have import pytest import MyPackage.MyModule ... Pytest is able to discover the tests and run

Pytest where to store expected data

二次信任 提交于 2020-07-04 06:19:27
问题 Testing function I need to pass parameters and see the output matches the expected output. It is easy when function's response is just a small array or a one-line string which can be defined inside the test function, but suppose function I test modifies a config file which can be huge. Or the resulting array is something 4 lines long if I define it explicitly. Where do I store that so my tests remain clean and easy to maintain? Right now if that is string I just put a file near the .py test

py.test capture unhandled exception

て烟熏妆下的殇ゞ 提交于 2020-06-29 05:26:59
问题 We are using py.test 2.8.7 and I have the below method which creates a separate log file for every test-case. However this does not handle unhandled Exceptions. So if a code snippet throws an Exception instead of failing with an assert, the stack-trace of the Exception is not logged into the separate file. Can someone please help me in how I could capture these Exceptions? def remove_special_chars(input): """ Replaces all special characters which ideally shout not be included in the name of a

ModuleNotFoundError with pytest

ε祈祈猫儿з 提交于 2020-06-24 11:43:05
问题 I want my tests folder separate to my application code. My project structure is like so myproject/ myproject/ myproject.py moduleone.py tests/ myproject_test.py myproject.py from moduleone import ModuleOne class MyProject(object) .... myproject_test.py from myproject.myproject import MyProject import pytest ... I use myproject.myproject since I use the command python -m pytest from the project root directory ./myproject/ However, then the imports within those modules fail with E