Skip to content

Instantly share code, notes, and snippets.

View hpk42's full-sized avatar

holger krekel hpk42

View GitHub Profile
# content of conftest.py
import pytest
@pytest.mark.tryfirst
def pytest_pyfunc_call(pyfuncitem):
marker = pyfuncitem.get_marker("skip_if_eval")
if marker is not None:
class Mapping:
def __getitem__(self, name):
location ~ \+f/ {
try_files $uri @proxy_to_app;
}
location ~ \+doc/ {
try_files $uri @proxy_to_app;
}
location / {
proxy_pass http://localhost:3141;
proxy_set_header X-outside-url $scheme://$host;
proxy_set_header X-Real-IP $remote_addr;
class TestGitHubAPI:
def test_user(self, vcr):
vcr.use_cassette('user')
resp = self.session.get('https://api.github.com/user',
auth=('user', 'pass'))
assert resp.json()['login'] is not None
@betamax_cassette("repo")
def test_repo(self):
resp = self.session.get(
etamax_cassette = pytest.mark.betamax_cassette
class TestGitHubAPI:
def test_user(self, session, vcr):
vcr.use_cassette('user')
resp = session.get('https://api.github.com/user',
auth=('user', 'pass'))
assert resp.json()['login'] is not None
import pytest
with pytest.FixtureContext("db", path="...") as db:
# work with db
any finalizers will be called at the end of the with statement
import pytest
def test_hello(tmpdir):
print "hello using", tmpdir
assert 0
if __name__ == "__main__":
pytest.main(["--pyargs", "x"])
(0)hpk@teta:~/p/pytest$ cat test_x.py
def test_assert():
x = 3
assert x == 4
(0)hpk@teta:~/p/pytest$ python -OO -m pytest test_x.py
WARNING: assertions which are not in test modules will be ignored because assert statements are not executed by the underlying Python interpreter (are you using python -O?)
============================= test session starts ==============================
platform linux2 -- Python 2.7.3 -- pytest-2.4.3.dev2
import execnet
def execnet_main(channel):
import inspect
import sys
f = sys._getframe()
frames = []
while f:
import pytest
import mock
@mock.patch("os.path.abspath")
def test_one(mock_abspath):
pass
@mock.patch("os.path.abspath")
def test_two(mock_abspath):
pass
(py33)hpk@teta:/tmp/test_gen0$ python mypytest.py -n1 test_x.py
============================= test session starts ==============================
platform linux -- Python 3.3.2 -- pytest-2.4.3.dev2
plugins: xdist, instafail, capturelog, cache
gw0 C[gw0] node down: Traceback (most recent call last):
File "/home/hpk/venv/py33/local/lib/python3.3/site-packages/execnet/gateway_base.py", line 800, in executetask
do_exec(co, loc)
File "<string>", line 1, in do_exec
File "<remote exec>", line 139, in <module>
File "<remote exec>", line 117, in remote_initconfig