Tuesday, March 6, 2012

py.test paremeterized test fails with "LookupError: no factory found for function argument …"


I have a trivial test:
import pytest
@pytest.mark.parameterize(("input", "expected"), [
    ("3+5", 8),
    ("2+4", 6),
    ("6*9", 42),
])
def test_eval(input, expected):
    assert eval(input) == expected
It fails saying:
LookupError: no factory found for function argument 'input'
available funcargs: pytestconfig, capsys, capfd, tmpdir, monkeypatch, recwarn
use 'py.test --funcargs [testpath]' for help on them.
What's going on here? It's spelt parametrize – not parameterize.

But why didn't I get a NameError?

pytest.mark allows arbitrary marks to be added to a function. Due to the
dynamic nature of py.test, pytest.mark.<any name here> can be used to mark a
test. Since pytest.mark.parameterize isn't recognised by any of the pytest
plugins, it's essentially a no-op.

Monday, March 5, 2012

Problem cloning local git repository using `git clone file:///…`

So I was trying to clone a local git repository using:
$ git clone file:///home/git/repositories/bar.git
And I would get output like this:
$ git clone file:///home/git/repositories/bar.git/ bar
Initialized empty Git repository in /home/brad/bar/.git
remote: Counting objects: 1317, done.
remote: Compressing objects: 100% (1179/1179), done.
remote: Total 1317 (delta 601), reused 406 (delta 57)
Receiving objects: 100% (1317/1317), 5.37 MiB | 683 KiB/s, done.
Resolving deltas: 100% (601/601), done.
warning: remote HEAD refers to nonexistent ref, unable to checkout.
The issue was that although I had added myself to the git group, the permissions on the heads refs did not permit group read:
$ ls -lha /home/git/repositories/bar.git/refs/heads
total 12K
drwx------ 2 git git 4.0K 2012-03-05 15:42 .
drwx------ 4 git git 4.0K 2012-02-28 14:21 ..
-rw------- 1 git git   41 2012-03-05 15:45 development
-rw------- 1 git git   41 2012-03-05 15:42 master
Simple fix:
$ chmod g+r /home/git/repositories/bar.git/refs/heads/*
So why was this suddenly a problem?

It just so happens I recently upgraded from gitosis to gitolite, and gitolite uses a different umask (0077) to gitosis. This means that every new file created was created with only user permissions.

I want g+rx, so I edited /home/git/.gitolite.rc and changed $REPO_UMASK to 0027.