python-unittest

Subprocesses not running with pytest Error Processing Test

巧了我就是萌 提交于 2020-03-05 05:01:06
问题 I am currently converting my unittest setup over to pytest, everything is working however on certain tests I run a command line process in order to load code into the hardware I have attached via USB. this process works fine with unittest however when using pytest or nose2 I get the response ------------------------------------------------ Captured stderr call ------------------------------------------------- Error processing Test this happens just when my process begins to run? I get no

Asserting that __init__ was called with right arguments

对着背影说爱祢 提交于 2020-02-21 09:46:13
问题 I'm using python mocks to assert that a particular object was created with the right arguments. This is how my code looks: class Installer: def __init__(foo, bar, version): # Init stuff pass def __enter__(self): return self def __exit__(self, type, value, tb): # cleanup pass def install(self): # Install stuff pass class Deployer: def deploy(self): with Installer('foo', 'bar', 1) as installer: installer.install() Now, I want to assert that installer was created with the right arguments. This

How to list available tests with python?

余生长醉 提交于 2020-02-01 03:09:27
问题 How to just list all discovered tests? I found this command: python3.4 -m unittest discover -s . But it's not exactly what I want, because the above command executes tests. I mean let's have a project with a lot of tests. Execution time is a few minutes. This force me to wait until tests are finished. What I want is something like this (above command's output) test_choice (test.TestSequenceFunctions) ... ok test_sample (test.TestSequenceFunctions) ... ok test_shuffle (test

Exception raised but not caught by assertRaises

岁酱吖の 提交于 2020-01-26 05:01:14
问题 I'm trying to test that my authentication fails. The exception is raised but not caught by assertRaises . What am I missing here? def test_auth(self): from graphql_jwt.exceptions import PermissionDenied with self.assertRaises(PermissionDenied): response = self.client.execute(self.query) Traceback: Creating test database for alias 'default'... System check identified no issues (0 silenced). Traceback (most recent call last): File "/home/dan/game/venv/lib/python3.7/site-packages/promise/promise

Python unittest: How to temporarily redirect stdout messages to a buffer and to test its content?

人走茶凉 提交于 2020-01-25 04:19:28
问题 I would like to capture messages sent to stdout (our stderr ) temporarily during a test and assert if some string patterns occurred in these messages: import unittest class SomeTest(unittest.TestCase): def test_stdout(self): output = "" function_that_writes_to_stdout() # How to capture stdout in output temporarily? self.assertIn("some message", output) I found a similar question, but the accepted answer suggests to capture messages sent to stdout for all test cases. Yes, I know that it's not

Mocking render to response with Pyramid

 ̄綄美尐妖づ 提交于 2020-01-24 22:07:55
问题 I have a decorator that looks like so: def validate_something(func): def validate_s(request): if request.property: render_to_response('template.jinja', 'error' return func(request) return validate_something I'm trying to test it like so. I load the local WSGI stack as an app. from webtest import TestApp def setUp(self): self.app = TestApp(target_app()) self.config = testing.setUp(request=testing.DummyRequest) def test_something(self): def test_func(request): return 1 request = testing

Mocking render to response with Pyramid

本小妞迷上赌 提交于 2020-01-24 22:06:15
问题 I have a decorator that looks like so: def validate_something(func): def validate_s(request): if request.property: render_to_response('template.jinja', 'error' return func(request) return validate_something I'm trying to test it like so. I load the local WSGI stack as an app. from webtest import TestApp def setUp(self): self.app = TestApp(target_app()) self.config = testing.setUp(request=testing.DummyRequest) def test_something(self): def test_func(request): return 1 request = testing

temp files/directories with custom names?

限于喜欢 提交于 2020-01-24 19:53:27
问题 How to create a temporary files/directories with user defined names in python. I am aware of tempfile . However I couldn't see any function with filename as argument. Note: I need this for unit testing the glob(file name pattern matching) functionality on a temporary directory containing temporary files rather than using the actual file system. 回答1: You can use open() with whatever file name you need. e.g. open(name, 'w') Open Or import os import tempfile print 'Building a file name yourself:

Attempted relative import beyond toplevel package

半城伤御伤魂 提交于 2020-01-20 02:16:50
问题 Here is my folder structure: Mopy/ # no init.py ! bash/ __init__.py bash.py # <--- Edit: yep there is such a module too bass.py bosh/ __init__.py # contains from .. import bass bsa_files.py ... test_bash\ __init__.py # code below test_bosh\ __init__.py test_bsa_files.py In test_bash\__init__.py I have: import sys from os.path import dirname, abspath, join, sep mopy = dirname(dirname(abspath(__file__))) assert mopy.split(sep)[-1].lower() == 'mopy' sys.path.append(mopy) print 'Mopy folder

Attempted relative import beyond toplevel package

爷,独闯天下 提交于 2020-01-20 02:16:48
问题 Here is my folder structure: Mopy/ # no init.py ! bash/ __init__.py bash.py # <--- Edit: yep there is such a module too bass.py bosh/ __init__.py # contains from .. import bass bsa_files.py ... test_bash\ __init__.py # code below test_bosh\ __init__.py test_bsa_files.py In test_bash\__init__.py I have: import sys from os.path import dirname, abspath, join, sep mopy = dirname(dirname(abspath(__file__))) assert mopy.split(sep)[-1].lower() == 'mopy' sys.path.append(mopy) print 'Mopy folder