python-unittest

Why am I getting “No tests discovered” with Python tests in VS Code?

社会主义新天地 提交于 2020-06-16 17:31:23
问题 This is my first few lines of code but I've coded for 20 years so I quickly wanted to get unit testing running. I am using Windows 10 VS Code 1.30.2 from 7th January, 2019. Python 3.7.2 Python Extension ms-python.python 2018.12.1 Here's the contents of the folder I'm in. Directory: C:\DATA\Git\Py\my_first_code Mode LastWriteTime Length Name ---- ------------- ------ ---- d----- 19/01/2019 21:42 __pycache__ -a---- 19/01/2019 21:35 289 messing.py -a---- 19/01/2019 21:42 204 test_messing.py -a--

Loading data from GCS using Spark Local

◇◆丶佛笑我妖孽 提交于 2020-05-31 04:08:06
问题 I am trying to read data from GCS buckets on my local machine, for testing purposes. I would like to sample some of the data in the cloud I have downloaded the GCS Hadoop Connector JAR. And setup the sparkConf as follow: conf = SparkConf() \ .setMaster("local[8]") \ .setAppName("Test") \ .set("spark.jars", "path/gcs-connector-hadoop2-latest.jar") \ .set("spark.hadoop.google.cloud.auth.service.account.enable", "true") \ .set("spark.hadoop.google.cloud.auth.service.account.json.keyfile", "path

assertEqual custom comparison of list item

自古美人都是妖i 提交于 2020-05-31 03:22:27
问题 In Python I would like to execute a custom comparison for a specific class. The function I have to test return a list containing objects created by a library that I don't have no control on it. The error (which make my test failing) is because of this specific object comparison. First differing element 0: The return is actually correct but the __eq__ function of the library object return False . class NotControlledClass: def __eq__(self, other): # Always return false as objects are created

assertEqual custom comparison of list item

我的未来我决定 提交于 2020-05-31 03:21:07
问题 In Python I would like to execute a custom comparison for a specific class. The function I have to test return a list containing objects created by a library that I don't have no control on it. The error (which make my test failing) is because of this specific object comparison. First differing element 0: The return is actually correct but the __eq__ function of the library object return False . class NotControlledClass: def __eq__(self, other): # Always return false as objects are created

assertEqual custom comparison of list item

主宰稳场 提交于 2020-05-31 03:21:06
问题 In Python I would like to execute a custom comparison for a specific class. The function I have to test return a list containing objects created by a library that I don't have no control on it. The error (which make my test failing) is because of this specific object comparison. First differing element 0: The return is actually correct but the __eq__ function of the library object return False . class NotControlledClass: def __eq__(self, other): # Always return false as objects are created

Check that an exception is correctly raised in Python 2.7?

独自空忆成欢 提交于 2020-05-30 02:17:29
问题 Does anyone know how to check that an exception is raised correctly? I need something that works in Python 2.7. The below 'assert' is not quite correct method to use from the Python unittest library: assert ( a_a0_getinst.add_port("iTCK", ISC.PortType_INPUT) ), "Can't add duplicate port" The error I get is: Traceback (most recent call last): File "test_010_module.py", line 157, in runTest a_a0_addinst = a_a0.add_instance( "A00", b_a0 ) File "/nfs/sc/disks/sc_dteg_2004/users/acheung1/dteg

How to mock uuid generation in a test case?

匆匆过客 提交于 2020-05-28 20:51:51
问题 I have a test case in which in the setUp, I create an object for which I want to mock the function uuid4 in the module uuid . TEST_UUIDS = ['uuid_{}'.format(i) for i in range(10000)] UUID_POOL = iter(TEST_UUIDS) def generate_uuid() -> str: return next(UUID_POOL) class MyTestCase(TestCase): def setUp(self, **kwargs): self._create_my_object @patch.object(uuid, 'uuid4', generate_uuid) def _create_my_object(self): # Create an object using a uuid My problem now is that when I run write two test

python 3.4 multiprocessing does not work with unittest

我是研究僧i 提交于 2020-05-27 06:22:10
问题 I have an unittest which is using multiprocessing. After upgrading from Python 3.2 to Python 3.4 I get following error. I can't find a hint, what was changed inside Python and what I have to change, to make my code running. Thanks in advance. Traceback (most recent call last): File "<string>", line 1, in <module> File "C:\Python341_64\lib\multiprocessing\spawn.py", line 106, in spawn_main exitcode = _main(fd) File "C:\Python341_64\lib\multiprocessing\spawn.py", line 116, in _main self =

Pytest - error vs fail

走远了吗. 提交于 2020-05-26 10:37:14
问题 Im migrating from PyUnit to Pytest, and I found, that Pytest, unlike PyUnit, does not distinguish fails and errors in test report in quick report while running tests (where dots are printed). How to teach Pytest do do it? UPDATE Seems like it is valid only for PyUnit tests executed with Pytest, thanks to flub for the clue. Code: import unittest class TestErrorFail(unittest.TestCase): def test_error(self): raise Exception('oops') def test_fail(self): self.assertTrue(False) Output: ============

Chromedriver closing after test

别来无恙 提交于 2020-05-15 08:37:09
问题 So my understanding is that calling driver.quit or close is the the proper way to close the driver and associated window. However when running my tests, it seems that even without calling driver.quit and instead calling pass, that the window still closes. I'm using python with unittest test cases excuted via pytest. I've also run standard unitests via Pycharm. In all scenarios, the browser closes as described. I want the browser to stay open to where I can debug tests. I could just call sleep