python-unittest

Why doesn't unittest.mock.ANY work correctly with Django objects?

ぃ、小莉子 提交于 2019-12-02 15:39:11
问题 I have written a test in Django, and I'm using unittest.mock.ANY to ignore certain values in a dictionary. Here is the test: from django.test import TestCase from django.contrib.auth import get_user_model import unittest.mock as mock class Example(TestCase): def test_example(self): user = get_user_model().objects.create_user(username='example') result = {'user': user, 'number': 42} self.assertEqual( result, {'user': mock.ANY, 'number': 42} ) If I run this test, I expect it to pass. Instead, I

How do I make coverage include not tested files?

冷暖自知 提交于 2019-12-02 15:32:05
I have just started writing some unit tests for a python project I have using unittest and coverage . I'm only currently testing a small proportion, but I am trying to work out the code coverage I run my tests and get the coverage using the following python -m unittest discover -s tests/ coverage run -m unittest discover -s tests/ coverage report -m The problem I'm having is that coverage is telling I have 44% code coverage and is only counting the files that: were tested in the unit tests (i.e., all the files that were not tested are missing and not in the overall coverage) were in the

What is unittest in selenium Python?

99封情书 提交于 2019-12-02 13:23:21
What is the meaning of lines 3,16,17,18 and 19 which are highlighted with *. Can someone explain what they do? I am new to python and programming import unittest from selenium import webdriver **class Iframe(unittest.TestCase):** def setUp(self): self.driver = webdriver.Firefox() def test_Iframe(self): driver = self.driver driver.maximize_window() driver.get('http://www.toolsqa.com/iframe-practice-page/') iframe1 = driver.find_element_by_id('IF1') driver.switch_to.frame(iframe1) driver.find_element_by_name('email').send_keys('xyz') driver.switch_to.default_content() list = driver.find_elements

Phantom tests after switching from unittest.TestCase to tf.test.TestCase

随声附和 提交于 2019-12-02 11:32:41
问题 The following code: class BoxListOpsTest(unittest.TestCase): """Tests for common bounding box operations.""" def test_area(self): corners = tf.constant([[0.0, 0.0, 10.0, 20.0], [1.0, 2.0, 3.0, 4.0]]) exp_output = [200.0, 4.0] boxes = box_list.BoxList(corners) areas = box_list_ops.area(boxes) with tf.Session() as sess: areas_output = sess.run(areas) np.testing.assert_allclose(areas_output, exp_output) if __name__ == '__main__': unittest.main() Is interpreted as a test case with a single test:

Why doesn't unittest.mock.ANY work correctly with Django objects?

久未见 提交于 2019-12-02 08:20:15
I have written a test in Django, and I'm using unittest.mock.ANY to ignore certain values in a dictionary . Here is the test: from django.test import TestCase from django.contrib.auth import get_user_model import unittest.mock as mock class Example(TestCase): def test_example(self): user = get_user_model().objects.create_user(username='example') result = {'user': user, 'number': 42} self.assertEqual( result, {'user': mock.ANY, 'number': 42} ) If I run this test, I expect it to pass. Instead, I get this failure: ====================================================================== FAIL: test

Python unittest passing arguments to parent test class

蹲街弑〆低调 提交于 2019-12-02 05:18:40
I have a parent test class named as basetestcase() This is inherited by all the test classes class BaseTestCase(unittest.TestCase): driver = None browser = read from command line operatingSystem = read from command line url = read from command line @classmethod def setUpClass(cls): """ SetUp to initialize webdriver session, pages and other needed objects Returns: None """ # Get webdriver instance # Browser should be read from the arguments if browser == "iexplorer": cls.driver = webdriver.Ie() elif browser == "firefox": cls.driver = webdriver.Firefox() elif browser == "chrome": cls.driver =

Selenium with Python-unittest - Test returns Process finished with exit code 0 and no action is performed

五迷三道 提交于 2019-12-02 04:00:19
问题 Could someone helping me to understand why the following code is executed, but no action is performed? Returned code is 0 but browser is not opened or no action is performed. it is worth to mention that setUp method has been configured in the same way in other modules and it works correctly. Please check at the end the response. import unittest from Init_load import set_up from selenium.webdriver.support import expected_conditions from selenium.webdriver.support.ui import WebDriverWait from

Selenium with Python-unittest - Test returns Process finished with exit code 0 and no action is performed

一曲冷凌霜 提交于 2019-12-02 00:38:47
Could someone helping me to understand why the following code is executed, but no action is performed? Returned code is 0 but browser is not opened or no action is performed. it is worth to mention that setUp method has been configured in the same way in other modules and it works correctly. Please check at the end the response. import unittest from Init_load import set_up from selenium.webdriver.support import expected_conditions from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.common.by import By class HomeTest(unittest.TestCase): def setUp(self): con = set_up

Python Selenium: wait until an element is no longer stale?

ぐ巨炮叔叔 提交于 2019-12-01 22:19:12
问题 I have a situation in which I want to wait until an element is no longer STALE i.e. until an elements gets connected to the DOM. Following wait options do not work somehow: self.wait.until(EC.visibility_of_element_located((By.ID, "elementID"))) self.wait.until(EC.presence_of_element_located((By.ID, "elementID"))) Its opposite wait function is present which waits until an element becomes stale, which is: self.wait.until(EC.staleness_of((By.ID, "elementID"))) But I want it to wait until the

Using unittest to test argparse - exit errors

徘徊边缘 提交于 2019-12-01 19:01:46
Going off of Greg Haskin's answer in this question , I tried to make a unittest to check that argparse is giving the appropriate error when I pass it some args that are not present in the choices . However, unittest generates a false positive using the try/except statement below. In addition, when I make a test using just a with assertRaises statement, argparse forces the system exit and the program does not execute any more tests. I would like to be able to have a test for this, but maybe it's redundant given that argparse exits upon error? #!/usr/bin/env python3 import argparse import