pytest fixtures in a separate directory

Please add the following in your conftest.py import pytest pytest_plugins = [ “fixtures.conftest”, “fixtures.fixture_cifs”, “fixtures.fixture_ftp”, “fixtures.fixture_service” ] This ensures that all fixtures declared under fixtures/ will be found by pytest As a note that the respective directories referred to in fixtures.conftest” need to have __init__.py files for the plugins to be loaded by pytest A … Read more

Generate Symfony2 fixtures from DB?

There’s no direct manner within Doctrine or Symfony2, but writing a code generator for it (either within or outside of sf2) would be trivial. Just pull each property and generate a line of code to set each property, then put it in your fixture loading method. Example: <?php $i = 0; $entities = $em->getRepository(‘MyApp:Entity’)->findAll(); foreach($entities … Read more

How to create fixtures (for a Devise user) as a yml.erb in rails (4.1.5)?

You should pass the password in plain text too. I am sure there is a User model validation errors preventing your fixture users from being created. Here’s an example from my users fixture which works: tom: first_name: Tom last_name: Test email: [email protected] password: 123greetings encrypted_password: <%= User.new.send(:password_digest, ‘123greetings’) %> If it still fails, please check … Read more

Rails fixtures — how do you set foreign keys?

You should use named fixtures, which automatically generate an id number for you where you don’t provide one. These id numbers are essentially integer hashes of whatever string you use. Don’t add the “_id” if you’re referencing the named version: # recipes.yml chicken_soup: cookbook: my_recipes # cookbooks.yml my_recipes: title: My Test Cookbook

Pytest use same fixture twice in one function

An alternative is just to copy the fixture function. This is both simple and correctly handles parameterized fixtures, calling the test function with all combinations of parameters for both fixtures. This example code below raises 9 assertions: import pytest @pytest.fixture(params=[0, 1, 2]) def first(request): return request.param second = first def test_double_fixture(first, second): assert False, ‘{} … Read more

Override a pytest parameterized functions name

You’re looking for the ids argument of pytest.mark.parametrize: list of string ids, or a callable. If strings, each is corresponding to the argvalues so that they are part of the test id. If callable, it should take one argument (a single argvalue) and return a string or return None. Your code would look like @pytest.mark.parametrize( … Read more

How to pass a parameter to a fixture function in Pytest?

This is actually supported natively in py.test via indirect parametrization. In your case, you would have: @pytest.fixture def tester(request): “””Create tester object””” return MyTester(request.param) class TestIt: @pytest.mark.parametrize(‘tester’, [[‘var1’, ‘var2’]], indirect=True) def test_tc1(self, tester): tester.dothis() assert 1

Fixtures in RSpec

If you want to use fixtures with RSpec, specify your fixtures in the describe block, not within a before block: describe StudentsController do fixtures :students before do # more test setup end end Your student fixtures will get loaded into the students table and then rolled back at the end of each test using database … Read more