python-unittest

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

随声附和 提交于 2019-12-01 18:47:39
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 element is NO LONGER STALE i.e. until it gets connected to the DOM. How can I achieve this functionality?

Using unittest to test argparse - exit errors

南楼画角 提交于 2019-12-01 18:40:32
问题 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

Python unittest mock: Is it possible to mock the value of a method's default arguments at test time?

谁都会走 提交于 2019-12-01 15:26:31
I have a method that accepts default arguments: def build_url(endpoint, host=settings.DEFAULT_HOST): return '{}{}'.format(host, endpoint) I have a test case that exercises this method: class BuildUrlTestCase(TestCase): def test_build_url(self): """ If host and endpoint are supplied result should be 'host/endpoint' """ result = build_url('/end', 'host') expected = 'host/end' self.assertEqual(result,expected) @patch('myapp.settings') def test_build_url_with_default(self, mock_settings): """ If only endpoint is supplied should default to settings""" mock_settings.DEFAULT_HOST = 'domain' result =

Recursive unittest discover

*爱你&永不变心* 提交于 2019-12-01 14:56:26
I have a package with a directory "tests" in which I'm storing my unit tests. My package looks like: . ├── LICENSE ├── models │ └── __init__.py ├── README.md ├── requirements.txt ├── tc.py ├── tests │ ├── db │ │ └── test_employee.py │ └── test_tc.py └── todo.txt From my package directory, I want to be able to find both tests/test_tc.py and tests/db/test_employee.py . I'd prefer not to have to install a third-party library ( nose or etc) or have to manually build a TestSuite to run this in. Surely there's a way to tell unittest discover not to stop looking once it's found a test? python -m

Recursive unittest discover

ぐ巨炮叔叔 提交于 2019-12-01 13:41:25
问题 I have a package with a directory "tests" in which I'm storing my unit tests. My package looks like: . ├── LICENSE ├── models │ └── __init__.py ├── README.md ├── requirements.txt ├── tc.py ├── tests │ ├── db │ │ └── test_employee.py │ └── test_tc.py └── todo.txt From my package directory, I want to be able to find both tests/test_tc.py and tests/db/test_employee.py . I'd prefer not to have to install a third-party library ( nose or etc) or have to manually build a TestSuite to run this in.

PyUnit - How to unit test a method that runs into an infinite loop for some input?

限于喜欢 提交于 2019-12-01 08:03:23
A post in 2011 answered this question for NUnit: How to unit test a method that runs into an infinite loop for some input? Is there a similar TimeoutAttribute in PyUnit that I can use in the same fashion? I did some searching and found "Duration", but that didn't seem the same. There doesn't appear there is anything in pyunit itself, but as a work around you can roll your own. Here is how to do it using the multiprocessing package. from functools import wraps from multiprocessing import Process class TimeoutError(Exception): pass def timeout(seconds=5, error_message="Timeout"): def decorator

testing postgres db python

我是研究僧i 提交于 2019-12-01 05:26:31
I don't understand how to test my repositories. I want to be sure that I really saved object with all of it parameters into database, and when I execute my SQL statement I really received what I am supposed to. But, I cannot put "CREATE TABLE test_table " in setUp method of unittest case because it will be created multiple times (tests of the same testcase are runned in parallel). So, as long as I create 2 methods in the same class which needs to work on the same table, it won't work (name clash of tables) Same, I cannot put "CREATE TABLE test_table" setUpModule , because, now the table is

testing postgres db python

≯℡__Kan透↙ 提交于 2019-12-01 02:52:20
问题 I don't understand how to test my repositories. I want to be sure that I really saved object with all of it parameters into database, and when I execute my SQL statement I really received what I am supposed to. But, I cannot put "CREATE TABLE test_table " in setUp method of unittest case because it will be created multiple times (tests of the same testcase are runned in parallel). So, as long as I create 2 methods in the same class which needs to work on the same table, it won't work (name

Pycharm and unittest does not work

半城伤御伤魂 提交于 2019-11-30 17:11:26
I have a problem with PYCharm 3.0.1 I can't run basic unittests. Here is my code : import unittest from MysqlServer import MysqlServer class MysqlServerTest(unittest.TestCase): def setUp(self): self.mysqlServer = MysqlServer("ip", "username", "password", "db", port) def test_canConnect(self): self.mysqlServer.connect() self.fail() if __name__ == '__main__': unittest.main() Here is All the stuff pycharm give me Unable to attach test reporter to test framework or test framework quit unexpectedly Is also says AttributeError: class TestLoader has no attribute '__init__' And the event log : 2:14:28

Python unittest.TestCase object has no attribute 'runTest'

霸气de小男生 提交于 2019-11-30 11:13:21
For the following code: import unittest class Test(unittest.TestCase): def test1(self): assert(True == True) if __name__ == "__main__": suite = unittest.TestSuite() suite.addTest(Test()) unittest.TextTestRunner().run(suite) Using Python 3 to execute it, the following error is raised: Traceback (most recent call last): File "test.py", line 10, in <module> unittest.TextTestRunner().run(suite) File "/usr/lib/python3.2/unittest/runner.py", line 168, in run test(result) File "/usr/lib/python3.2/unittest/suite.py", line 67, in __call__ return self.run(*args, **kwds) File "/usr/lib/python3.2/unittest