How to use the py.test.raises function in py

To help you get started, we’ve selected a few py examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github pytest-dev / pytest / testing / execnet / test_xspec.py View on Github external
def test_samekeyword_twice_raises(self):
        py.test.raises(ValueError, "XSpec('popen//popen')")
        py.test.raises(ValueError, "XSpec('popen//popen=123')")
github holzschu / python3_ios / extraPackages / cffi-1.11.5 / testing / cffi0 / test_function.py View on Github external
if self.Backend is CTypesBackend:
            py.test.skip("not with the ctypes backend")
        ffi = FFI(backend=self.Backend())
        ffi.cdef("int foobar(void); int foobaz;")
        lib = ffi.dlopen(lib_m)
        ffi.dlclose(lib)
        e = py.test.raises(ValueError, ffi.dlclose, lib)
        assert str(e.value).startswith("library '")
        assert str(e.value).endswith("' has already been closed")
        e = py.test.raises(ValueError, getattr, lib, 'foobar')
        assert str(e.value).startswith("library '")
        assert str(e.value).endswith("' has already been closed")
        e = py.test.raises(ValueError, getattr, lib, 'foobaz')
        assert str(e.value).startswith("library '")
        assert str(e.value).endswith("' has already been closed")
        e = py.test.raises(ValueError, setattr, lib, 'foobaz', 42)
        assert str(e.value).startswith("library '")
        assert str(e.value).endswith("' has already been closed")
github tiddlyweb / tiddlyweb / test / test_store_bag.py View on Github external
def test_failed_get():
    bag = Bag(name='bagnine')
    with py.test.raises(NoBagError):
        store.get(bag)
github clalancette / oz / tests / ozutil / test_ozutil.py View on Github external
def test_exe_exists_foo():
    with py.test.raises(Exception):
        oz.ozutil.executable_exists('foo')
github web-platform-tests / wpt / tools / six / test_six.py View on Github external
def test_get_method_self():
    class X(object):
        def m(self):
            pass
    x = X()
    assert six.get_method_self(x.m) is x
    py.test.raises(AttributeError, six.get_method_self, 42)
github holzschu / python3_ios / extraPackages / cffi-1.11.5 / testing / cffi1 / test_dlopen.py View on Github external
def test_no_cross_include():
    baseffi = FFI()
    baseffi.set_source('test_no_cross_include_base', "..source..")
    #
    ffi = FFI()
    ffi.include(baseffi)
    target = udir.join('test_no_cross_include.py')
    py.test.raises(VerificationError, make_py_source,
                   ffi, 'test_no_cross_include', str(target))
github pytest-dev / pytest / testing / io_ / test_capture.py View on Github external
def test_simple_fail_second_start(self, tmpfile):
        fd = tmpfile.fileno()
        cap = py.io.FDCapture(fd)
        f = cap.done()
        py.test.raises(ValueError, cap.start)
        f.close()
github tiddlyweb / tiddlyweb / test / test_store_tiddler.py View on Github external
def test_put_no_bag():
    tiddler = Tiddler('hi')
    with py.test.raises(NoBagError):
        store.put(tiddler)
github mozillazg / pypy / extra_tests / cffi_tests / cffi1 / test_recompiler.py View on Github external
lib.my_value = 42                    # [2]
    assert values[2] == 42
    assert p[-1] == 41
    assert p[+1] == 42
    #
    # if get_my_value raises or returns nonsense, the exception is printed
    # to stderr like with any callback, but then the C expression 'my_value'
    # expand to '*NULL'.  We assume here that '&my_value' will return NULL
    # without segfaulting, and check for NULL when accessing the variable.
    @ffi.callback("int *(*)(void)")
    def get_my_value():
        raise LookupError
    lib.get_my_value = get_my_value
    py.test.raises(ffi.error, getattr, lib, 'my_value')
    py.test.raises(ffi.error, setattr, lib, 'my_value', 50)
    py.test.raises(ffi.error, ffi.addressof, lib, 'my_value')
    @ffi.callback("int *(*)(void)")
    def get_my_value():
        return "hello"
    lib.get_my_value = get_my_value
    py.test.raises(ffi.error, getattr, lib, 'my_value')
    e = py.test.raises(ffi.error, setattr, lib, 'my_value', 50)
    assert str(e.value) == "global variable 'my_value' is at address NULL"
github holzschu / python3_ios / extraPackages / cffi-1.11.5 / testing / cffi0 / test_ffi_backend.py View on Github external
def test_new_handle(self):
        ffi = FFI(backend=self.Backend())
        o = [2, 3, 4]
        p = ffi.new_handle(o)
        assert ffi.typeof(p) == ffi.typeof("void *")
        assert ffi.from_handle(p) is o
        assert ffi.from_handle(ffi.cast("char *", p)) is o
        py.test.raises(RuntimeError, ffi.from_handle, ffi.NULL)