Skip to content

Instantly share code, notes, and snippets.

View hackebrot's full-sized avatar
💻
Focusing

Raphael Aurich hackebrot

💻
Focusing
View GitHub Profile
@hackebrot
hackebrot / test_skipif.py
Created November 15, 2014 11:22
py.test skipif reasons
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import pytest
first_condition = False
second_condition = True
@hackebrot
hackebrot / create_tests.sh
Created November 4, 2015 17:13
create pytest tests
#! /usr/bin/env bash
set -e
set -u
set -x
for testdir in foobar hello/world example
do
mkdir -p $testdir
for i in {1..3}
@hackebrot
hackebrot / conftest.py
Last active February 1, 2016 22:55
pytest magic
def pytest_collection_modifyitems(items, config):
selected_items = []
deselected_items = []
for item in items:
if 'new_fixture' in getattr(item, 'fixturenames', ()):
selected_items.append(item)
else:
deselected_items.append(item)
config.hook.pytest_deselected(items=deselected_items)
@hackebrot
hackebrot / new_context.json
Created June 4, 2016 16:22
cookiecutter.json draft
{
"author": "Raphael Pierzina",
"keywords": [
"pytest",
"plugin"
],
"url": "https://github.com/pytest-dev/cookiecutter-pytest-plugin",
"variables": [
{
"default": "Raphael Pierzina",
@hackebrot
hackebrot / rename
Created August 1, 2016 07:42
rename in files
$ ag -w foo -l -0 | xargs -0 -n 1 sed -i '' -e 's/foo/bar/g'
@hackebrot
hackebrot / conftest.py
Last active August 3, 2016 07:18
Report tests as failures
# -*- coding: utf-8 -*-
import random
import pytest
@pytest.hookimpl(hookwrapper=True)
def pytest_runtest_makereport(item):
outcome = yield
rep = outcome.get_result()
@hackebrot
hackebrot / skipping.py
Last active August 5, 2016 17:35
1546
elif call.when == "call":
strict_default = item.config.getini('xfail_strict')
is_strict_xfail = evalxfail.get('strict', strict_default)
# TODO: xpass outcome
if is_strict_xfail:
rep.outcome = "failed"
else:
rep.outcome = "passed"
rep.wasxfail = evalxfail.getexplanation()
@hackebrot
hackebrot / conftest.py
Last active August 11, 2016 14:44
Skipped test should be an error
@pytest.hookimpl(hookwrapper=True)
def pytest_runtest_makereport(item, call):
outcome = yield
rep = outcome.get_result()
if pytest.config.getoption('--error-for-skips'):
if rep.skipped and call.excinfo.errisinstance(pytest.skip.Exception):
rep.outcome = 'failed'
r = call.excinfo._getreprcrash()
rep.longrepr = 'Skipped test - {message}'.format(message=r.message)
addprx = "!f() { b=`git symbolic-ref -q --short HEAD` && \
echo \"Making branch for pull request #$1 [pr/$1]\" && \
git fetch origin pull/$1/head:pr/$1 && \
echo \"Rebasing pr/$1 onto $b...\" && \
git fetch -q -f origin pull/$1/merge:refs/PR_MERGE_HEAD && \
git rebase -q --onto $b PR_MERGE_HEAD^ pr/$1 && \
git checkout -q $b && echo && \
git diff --stat $b..pr/$1 && echo && \
git log --oneline $b..pr/$1; \
git update-ref -d refs/PR_MERGE_HEAD; \
@hackebrot
hackebrot / Makefile
Created February 14, 2017 23:57
gvt fetch for existing project
.DEFAULT_GOAL := help
define filterstdlib
go list -f '{{ if not .Standard }}{{ .ImportPath }}{{ end }}'
endef
define getimports
go list -f '{{ join .Imports "\n" }}'
endef