python-unittest

Is there a way to hook Django's unittest into PyUnit in eclipse?

旧城冷巷雨未停 提交于 2019-12-20 10:49:12
问题 I've been working on a Django project for the past few weeks now, and it's been fairly smooth sailing. I use Django's unittest library to test everything, and the result show up in the console. However, after doing some research, it looks like pydev provides facilities for PyUnit . I use Eclipse, and I thought I would just just be able to pipe the unit tests into PyUnit, but I haven't had any luck in either that or finding documentation to do so. How do I have my unit tests run in the PyUnit

How to run Tox with Travis-CI

丶灬走出姿态 提交于 2019-12-20 09:29:38
问题 How do you test different Python versions with Tox from within Travis-CI? I have a tox.ini : [tox] envlist = py{27,33,34,35} recreate = True [testenv] basepython = py27: python2.7 py33: python3.3 py34: python3.4 py35: python3.5 deps = -r{toxinidir}/pip-requirements.txt -r{toxinidir}/pip-requirements-test.txt commands = py.test which runs my Python unittests in several Python versions and works perfectly. I want to setup a build in Travis-CI to automatically run this when I push changes to

Python Mock with `from X import y`

瘦欲@ 提交于 2019-12-20 05:51:33
问题 I am trying to use Python's mock library in my unit testing but I am seeing inconsistent results depending on how I import the target that I am trying to patch. I would expect that both of these print statements should return False but it appears that only the second statement returns False : from requests import get import requests with mock.patch('requests.get') as get_mock: get_mock.return_value.ok = False print get('http://asdf.com').ok print requests.get('http://asdf.com').ok 回答1:

Python + WebDriver — No browser launched while using unittest module

梦想的初衷 提交于 2019-12-20 05:13:10
问题 Could you please help me with the next. I found out the issue and could not resolve it. When I am using next code, the browser has started and the test has passed: import unittest from selenium import webdriver driver = webdriver.Chrome('D:\chromedriver\chromedriver.exe') driver.get("site URL") BUT same with class and methods return message: "Process finished with exit code 0": import unittest from selenium import webdriver class GlossaryPage(unittest.TestCase): def setUp(self): self.driver =

Python Unit Test : How to unit test the module which contains database operations?

这一生的挚爱 提交于 2019-12-18 17:32:08
问题 I am using pymysql client library to connect to the real database. I have a function in module, where I connect to the database using pymysql and do only database insert operations.How to unit test this function in python without hitting the real database? import pymysql def connectDB(self): # Connect to the database connection = pymysql.connect(host='localhost', user='user', password='passwd', db='db') try: with connection.cursor() as cursor: # Create a new record sql = "INSERT INTO `users`

patching a class yields “AttributeError: Mock object has no attribute” when accessing instance attributes

坚强是说给别人听的谎言 提交于 2019-12-18 11:40:48
问题 The Problem Using mock.patch with autospec=True to patch a class is not preserving attributes of instances of that class. The Details I am trying to test a class Bar that instantiates an instance of class Foo as a Bar object attribute called foo . The Bar method under test is called bar ; it calls method foo of the Foo instance belonging to Bar . In testing this, I am mocking Foo , as I only want to test that Bar is accessing the correct Foo member: import unittest from mock import patch

How can I check if a checkbox is checked in Selenium Python Webdriver?

回眸只為那壹抹淺笑 提交于 2019-12-18 10:39:43
问题 I'm searching a week how check if a checkbox is checked in selenium webdriver with python, but I find only algoritms from JAVA. I readed the webdriver docs and it dont have a answer for that. Anyone have a solution? 回答1: There is a WebElement property called is_selected() , and for a check box this indicates whether or not it is checked. Therefore you can verify if it is checked/unchecked by doing something like this: driver.find_element_by_name('<check_box_name>').is_selected() or driver

What is the difference between setUp() and setUpClass() in Python unittest?

只愿长相守 提交于 2019-12-17 21:42:03
问题 What is the difference between setUp() and setUpClass() in the Python unittest framework? Why would setup be handled in one method over the other? I want to understand what part of setup is done in the setUp() and setUpClass() functions, as well as with tearDown() and tearDownClass() . 回答1: The difference manifests itself when you have more than one test method in your class. setUpClass and tearDownClass are run once for the whole class; setUp and tearDown are run before and after each test

Trying to implement python TestSuite

青春壹個敷衍的年華 提交于 2019-12-17 18:16:05
问题 I have two test cases (two different files) that I want to run together in a Test Suite. I can get the tests to run just by running python "normally" but when I select to run a python-unit test it says 0 tests run. Right now I'm just trying to get at least one test to run correectly. import usertest import configtest # first test import unittest # second test testSuite = unittest.TestSuite() testResult = unittest.TestResult() confTest = configtest.ConfigTestCase() testSuite.addTest(configtest

Testing a function call inside the function using python unittest framework

天大地大妈咪最大 提交于 2019-12-13 20:49:32
问题 I want to test this class using python unittest framework and also mockito. class ISightRequestEngine(object): def __init__(self, pInputString=None): self.__params = (pInputString) def openHTTPConnection(self): pass def __closeHTTPConnection(self): pass def testFunc(self): print 'test function called' def startEngine(self): self.__params.parseinputString() self.openHTTPConnection() self.testFunc() def processRequest(self, header = None): pass I wanted to test that function startEngine() calls