python-unittest

ImportError: No module named zlib; tox

随声附和 提交于 2019-12-08 07:48:50
问题 I am trying to run tox tests as python 2.6. I just installed 2.6 and am now getting past the "Interpreter error: no python 2.6" style error, but tox is now crashing at zlib. Zlib is on my machine however. My tox issue looks like: $ tox -e py26 GLOB sdist-make: /home/cchilders/work_projects/webapi/setup.py py26 create: /home/cchilders/work_projects/webapi/.tox/py26 ERROR: invocation failed (exit code 1), logfile: /home/cchilders/work_projects/webapi/.tox/py26/log/py26-0.log ERROR: actionid:

Is this a proper way to test stdout with Python 3 unittest?

寵の児 提交于 2019-12-08 05:34:21
问题 Suppose I have a submission file, fileFromStudent.py , and the only thing in it is: print("hello world") I would like to test the stdout to see if the student has properly written out the print statement. Based on what I've read, I've been able to create the following code: from io import StringIO from unittest.mock import patch import unittest, importlib, sys class TestStringMethods(unittest.TestCase): def setUp(self): studentSubmission = 'fileFromStudent' ## Stores output from print() in

Command-line invocation of unittests from __main__ failing

橙三吉。 提交于 2019-12-08 04:23:40
问题 I am solving some exercises in Python and using unittest to automate some of the verification of my code. One program runs the single unittest just fine and it passes. The second gives the following error: $ python s1c6.py E ====================================================================== ERROR: s1c6 (unittest.loader._FailedTest) ---------------------------------------------------------------------- AttributeError: module '__main__' has no attribute 's1c6' ------------------------------

Mock function from other module

本小妞迷上赌 提交于 2019-12-08 04:00:22
问题 I have two python files: function.py: def foo (): return 20 def func (): temp = foo() return temp and mocking.py: from testing.function import * import unittest import mock class Testing(unittest.TestCase): def test_myTest(self): with mock.patch('function.func') as FuncMock: FuncMock.return_value = 'string' self.assertEqual('string', func()) I want to mock func, but with no positive result. I have AssertionError: 'string' != 20. What should I do to mock it correctly ? If I do mock.patch (

Django Tests run faster with no internet connection

邮差的信 提交于 2019-12-07 23:07:02
问题 I have a django test suite that builds a DB from a 400 line fixture file. It runs unfortunately slow. Several seconds per test. I was on the train yesterday developing without internet access, with my wifi turned off, and I noticed my tests ran literally 10x faster without internet. And they are definitely running correctly. Everything is local, it all runs fine without an internet connection. The tests themselves do not hit any APIs or make any other connections, so it seems it must be

If I have multiple tests in one class and a preceding test fails, how do I have it skip or exit the class instead of testing the remaining tests?

限于喜欢 提交于 2019-12-07 11:57:15
问题 I'm using Python with Selenium and unittest. I have four tests in one class since they're all related unit tests. How do I have it skip the next test(s) if the preceding test fails? I've read up on all the documentation for unittest's skip methods, but none of it is exactly what I need. Is there a way to tell it to exit the class? Here is a jist of what my code currently looks like: def test_dealer_search_id_contains(self): try: LoginPage.login(self, ULV.AA_USERNAME, ULV.AA_PASSWORD) except

Is this a proper way to test stdout with Python 3 unittest?

泄露秘密 提交于 2019-12-06 21:34:25
Suppose I have a submission file, fileFromStudent.py , and the only thing in it is: print("hello world") I would like to test the stdout to see if the student has properly written out the print statement. Based on what I've read, I've been able to create the following code: from io import StringIO from unittest.mock import patch import unittest, importlib, sys class TestStringMethods(unittest.TestCase): def setUp(self): studentSubmission = 'fileFromStudent' ## Stores output from print() in fakeOutput with patch('sys.stdout', new=StringIO()) as self.fakeOutput: ## Loads submission on first test

Instantiate Python unittest.TestCase with arguments

拈花ヽ惹草 提交于 2019-12-06 18:28:05
问题 I would like to iterate over a list of items, and run an assertion on each of them. One example might be checking whether each number in a list is odd. TestCase : class TestOdd(unittest.TestCase): def runTest(self): """Assert that the item is odd""" self.assertTrue( NUMBER %2==1, "Number should be odd") Test suite : if __name__ == '__main__': suite = unittest.TestSuite() suite.addTest(TestOdd()) # I would like to have: # suite.addTest(TestOdd(1)) # suite.addTest(TestOdd(2)) # suite.addTest

Django test tables are not being created

◇◆丶佛笑我妖孽 提交于 2019-12-06 13:50:23
I'm trying to write test cases for my django project but when I run "$ ./manage.py test" command its creating test database but its not creating any tables and I'm getting an error that table does't exists. Any suggestions are welcome. Here is my model which i have created through "./manage.py inspectdb > models.py" class MyCustomModel(models.Model): name = models.CharField(max_length=200) last_name = models.CharField(max_length=200) class Meta: managed = False db_table = 'MY_TABLE' Your table is unmanaged ( managed = False ) so it does not get created automatically during migration or testing

Python unittest counting the number of tests

筅森魡賤 提交于 2019-12-06 13:43:43
It's my first time playing around with Python's unittest for an assignment in school. I basically have a Circle Object, where I am using pyunit to make sure the data is stored properly. I noticed that Python only counts the number of methods as test cases as opposed to the number of assert statements. For instance I want to test that methods are working correctly, Python only counts the following as 2 tests, despite having 4 assert statements. It really caught me off guard, as with Java's JUnit it will count the number of assert statements instead. def test_xcrd(self): self.assertTrue(self