Questions tagged [fixtures]

Fixtures are scopes used for running tests which isolate each test from global namespace pollution and side-effects from previous tests in order to avoid false positives and false negatives

Filter by
Sorted by
Tagged with
572 votes
6 answers
251k views

What is conftest.py for in Pytest?

I'm trying to understand what conftest.py files are meant to be used for. In my (currently small) test suite I have one conftest.py file at the project root. I use it to define the fixtures that I ...
Aviv Cohn's user avatar
  • 16.4k
349 votes
6 answers
140k views

What are fixtures in programming?

I have heard of this term many times (in the context of programming) but couldn't find any explanation of what it meant. Any good articles or explanations?
Matjaz Muhic's user avatar
  • 5,458
265 votes
14 answers
282k views

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

I am using py.test to test some DLL code wrapped in a python class MyTester. For validating purpose I need to log some test data during the tests and do more processing afterwards. As I have many ...
maggie's user avatar
  • 4,145
124 votes
18 answers
56k views

Problems with contenttypes when loading a fixture in Django

I am having trouble loading Django fixtures into my MySQL database because of contenttypes conflicts. First I tried dumping the data from only my app like this: ./manage.py dumpdata escola > ...
gerdemb's user avatar
  • 11.4k
99 votes
4 answers
35k views

pytest fixtures Redefining name from outer scope [pylint]

I'm learning pytest and I lint my code with pylint. But pylint still complaints about: W0621: Redefining name %r from outer scope (line %s) for the following example from pytest: # test_wallet.py @...
oglop's user avatar
  • 1,275
94 votes
6 answers
97k views

How to create a fixture file

I want to create a fixture file in my Django project. How can I do this?
Viktor Apoyan's user avatar
85 votes
1 answer
19k views

How do I escape the ERB tag in ERB

I have a simple fixture.yml file: label: body: "<%= variable %>" The issue is that the ERB code is parsed as part of loading the fixture, whereas I actually want the body to be literally "&...
Daniel's user avatar
  • 7,064
71 votes
7 answers
47k views

@Patch decorator is not compatible with pytest fixture

I have encountered something mysterious, when using patch decorator from mock package integrated with pytest fixture. I have two modules: -----test folder -------func.py -------...
Hello lad's user avatar
  • 18k
70 votes
4 answers
22k views

Django: Create fixtures without specifying a primary key?

One of the things that bugs me about Django fixtures is that you've got to specify every model's primary key. Is there any way to create fixtures without having to specify a primary key for each row?
David Wolever's user avatar
69 votes
5 answers
47k views

How to pass arguments to pytest fixtures?

The baseline of all my tests is that there will always be a taxi with at least one passenger in it. I can easily achieve this setup with some basic fixtures: from blah import Passenger, Taxi @pytest....
pyzzled's user avatar
  • 691
63 votes
5 answers
48k views

In which order are pytest fixtures executed?

For an application I'm testing I'd like to create an autouse=True fixture which monkeypatches smtplib.SMTP.connect to fail tests if they try to send an email unexpectedly. However, in cases where I ...
ThiefMaster's user avatar
58 votes
4 answers
12k views

How do I prevent fixtures from conflicting with django post_save signal code?

In my application, I want to create entries in certain tables when a new user signs up. For instance, I want to create a userprofile which will then reference their company and some other records for ...
poswald's user avatar
  • 1,765
57 votes
9 answers
47k views

Loading fixtures in django unit tests

I'm trying to start writing unit tests for django and I'm having some questions about fixtures: I made a fixture of my whole project db (not certain application) and I want to load it for each test, ...
gleb.pitsevich's user avatar
50 votes
6 answers
33k views

Load and use fixture in rails console

I wonder if there's a way to load and/or use fixture in rails console. Actually, I'd like to create a user from my fixture users.yml to do some testing without having to go through all the "pain" of ...
Patrick Pruneau's user avatar
47 votes
3 answers
41k views

How and where does py.test find fixtures

Where and how does py.test look for fixtures? I have the same code in 2 files in the same folder. When I delete conftest.py, cmdopt cannot be found running test_conf.py (also in same ...
Dave's user avatar
  • 4,224
45 votes
4 answers
11k views

When to use pytest fixtures?

I'm new to testing and I've stumbled across pytest fixtures, but I'm not entirely sure when to use them and why they're useful. For example, see the below code: import pytest @pytest.fixture def ...
the man's user avatar
  • 1,271
42 votes
10 answers
16k views

Using factory_girl in Rails with associations that have unique constraints. Getting duplicate errors

I'm working with a Rails 2.2 project working to update it. I'm replacing existing fixtures with factories (using factory_girl) and have had some issues. The problem is with models that represent ...
Mark Eric's user avatar
  • 773
42 votes
2 answers
27k views

difference between fixture and yield_fixture in pytest

I am going through pytest fixtures, and the following looks pretty similar, latest works pretty similar. Yes, the readability is better in yield_fixure, however could someone let me know what ...
Gaurang Shah's user avatar
  • 12.4k
40 votes
4 answers
28k views

In Django, getting a "Error: Unable to serialize database" when trying to dump data?

I'm getting an error when I'm trying to dump data to a JSON fixture in Djanog 1.2.1 on my live server. On the live server it's running MySQL Server version 5.0.77 and I imported a lot of data to my ...
littlejim84's user avatar
  • 9,171
39 votes
3 answers
22k views

Override a pytest parameterized functions name

My parameters determine the name of my parameterized pytest. I will be using a some randomized params for these tests. In order for my reporting names in junit to not get messed up, I'd like to create ...
SomeGuyOnAComputer's user avatar
39 votes
5 answers
14k views

Unit testing: Is it a good practice to have assertions in setup methods?

In unit testing, the setup method is used to create the objects needed for testing. In those setup methods, I like using assertions: I know what values I want to see in those objects, and I like to ...
avandeursen's user avatar
  • 8,538
37 votes
2 answers
11k views

Factory Girl + Mongoid embedded documents in fixtures

Let’s say you have the following mongoid documents: class User include Mongoid::Document embeds_one :name end class UserName include Mongoid::Document field :first field :...
GTDev's user avatar
  • 5,498
37 votes
6 answers
14k views

Pytest use same fixture twice in one function

For my web server, I have a login fixture that create a user and returns the headers needed to send requests. For a certain test, I need two users. How can I use the same fixture twice in one function?...
danijar's user avatar
  • 33.4k
36 votes
4 answers
26k views

pytest fixtures in a separate directory

I'm looking to create a pytest structure where I can separate the fixtures from the tests completely. The reason for this separation is that I want to include the fixtures directory as an external ...
Jakob Pogulis's user avatar
36 votes
3 answers
44k views

Fixtures in RSpec

I'm new to using RSpec for writing tests in a Rails application which uses a MySQL database. I have defined my fixtures and am loading them in my spec as follows: before(:all) do fixtures :student ...
Kris's user avatar
  • 1,413
33 votes
2 answers
10k views

Rails fixtures -- how do you set foreign keys?

I'm reading about Rails fixtures in this guide (thanks, trevorturk). It appears you define classes in a Yaml file and they're automatically loaded into the test DB -- cool. But if you want to specify ...
Ethan's user avatar
  • 58.9k
33 votes
4 answers
13k views

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

Update 3: It seems like this is specific to fixtures in a .yml.erb - even if I have no templated code, it seems like fixtures in a yml.erb file doesn't get loaded. Having a plain .yml file works. This ...
Anand's user avatar
  • 3,700
32 votes
7 answers
14k views

Generate Symfony2 fixtures from DB?

Is it possible to generate fixtures from an existing DB in Symfony2/Doctrine? How could I do that? Example: I have defined 15 entities and my symfony2 application is working. Now some people are ...
Stuck's user avatar
  • 11.9k
30 votes
4 answers
27k views

How can I load fixtures from functional test in Symfony 2

My DoctrineFixturesBundle is installed and I can load fixture trough the command-line but , how can I load fixtures from my functional test ?
Ousmane's user avatar
  • 2,763
30 votes
3 answers
25k views

Why cant unittest.TestCases see my py.test fixtures?

I'm trying to use py.test's fixtures with my unit tests, in conjunction with unittest. I've put several fixtures in a conftest.py file at the top level of the project (as described here), decorated ...
Will's user avatar
  • 4,451
28 votes
11 answers
22k views

Symfony 3.4.0 Could not find any fixture services to load

I am using Symfony 3.4.0, I try to load fixtures with: php bin/console doctrine:fixtures:load An error occurred while creating the data, what's wrong?
Alexander's user avatar
  • 311
28 votes
3 answers
24k views

Rails Fixtures not loading with rspec

So, I'm trying to learn the rspec BDD testing framework in the context of a rails project. The problem I'm having is that I can't, for the life of me, get my fixtures to load properly in rspec ...
Fishtoaster's user avatar
  • 1,809
28 votes
2 answers
7k views

Rails fixtures vs seeds

I'm learning Ruby on Rails, and I'd like to just make sure I understand the difference between fixtures and seed data. What I understand is that fixtures are basically test data that you run your ...
user2258651's user avatar
28 votes
1 answer
17k views

Django - Foreign Keys in Fixtures

I have a fixture of "User" objects (just the default Django auth ones), and am trying to create a fixture of "Profile" objects. Each profile has a one-to-one relation to a user object, and defines ...
numegil's user avatar
  • 1,916
27 votes
4 answers
10k views

Functional testing with Rails and Devise. What to put in my fixtures?

Hi I'm wanting to do some functional testing of my Rails 3 app that uses Devise and CanCan. In my User model I have the users age, I want to test that a user can only visit a certain page if they are:...
Jez Caudle's user avatar
26 votes
3 answers
25k views

Is it possible to load doctrine fixtures without deleting database

I have defined some fixtures in doctrine. When i try to run using this php app/console doctrine:fixtures:load then it asks me to purge the database. is it possible to load it without purging ...
user1994660's user avatar
  • 5,423
26 votes
4 answers
7k views

How do I set up my fixtures for a has_and_belongs_to_many relation?

I have the following models: class Company < ActiveRecord::Base has_and_belongs_to_many :regions class Region < ActiveRecord::Base has_many :requests has_and_belongs_to_many :companies ...
Peter Evjan's user avatar
  • 2,433
25 votes
4 answers
14k views

Why would a pytest factory as fixture be used over a factory function?

In the py.test docs it describes declaring factory methods as fixtures, like-so: @pytest.fixture def make_foo(): def __make_foo(name): foo = Foo() foo.name = name return ...
Ben Reed's user avatar
  • 864
23 votes
3 answers
2k views

In Rails 3, I'm getting a NoMethodError for the recycle! method during testing

I've got a functional test that's using fixtures. I also am using fixtures in my Unit tests, but they work without flaw. When running the functional tests, I get a: NoMethodError: undefined method '...
the_gastropod's user avatar
23 votes
1 answer
12k views

How do Django Fixtures handle ManyToManyFields?

I'm trying to load in around 30k xml files from clinicaltrials.gov into a mySQL database, and the way I am handling multiple locations, keywords, etc. are in a separate model using ManyToManyFields. ...
CMaury's user avatar
  • 1,283
23 votes
1 answer
14k views

TypeError: missing 1 required positional argument while using pytest fixture [duplicate]

I have written my test classes in a file and I am trying to use pytest fixtures so that I don't have to create the same input data in each test functions. Below is the minimal working example. import ...
Peaceful's user avatar
  • 5,130
22 votes
2 answers
5k views

Do fixtures trigger model callbacks?

Say I have a User model with the following code in User.rb: before_create :create_dependencies after_create :build_inbox And I also have a users.yml file with a bunch of user fixtures defined in it. ...
cakeforcerberus's user avatar
20 votes
4 answers
25k views

How to call a fixture from another fixture in Pytest?

I have a fixture that is returning an object of certain type and I have another fixture defined in another file that basically uses the object to do other things. But I am not able to return the ...
AYa's user avatar
  • 473
20 votes
3 answers
7k views

Migrating Django fixtures?

I have a Django application. I have .json fixture files containing test data, with unit tests that use the data to confirm the application is working properly. I also use South to migrate my ...
Ned Batchelder's user avatar
19 votes
3 answers
6k views

Loading Rails Fixtures in a Specific Order when Testing

Is there a way to load Rails fixtures in a specific order while running tests? For example, take the following classes... class User < ActiveRecord::Base has_many :memberships has_many :groups,...
Steven Blair's user avatar
19 votes
1 answer
25k views

pytest-mock mocker in pytest fixture

I'm trying to find out why I don't seem to be able to use a mocked return value in a fixture. With the following imports import pytest import uuid pytest-mock example that works: def test_mockers(...
ehindy's user avatar
  • 439
19 votes
3 answers
10k views

How to concatenate several parametrized fixtures into a new fixture in py.test?

If I have two parametrized fixtures, how can I create a single test function that is called first with the instances of one fixture and then with the instances of the other fixture? I guess it would ...
Matthias's user avatar
  • 4,674
19 votes
1 answer
10k views

Is there way to directly reference to a pytest fixture from a simple (non test) function?

Is there a way to reference (and call into) a pytest fixture from a simple function that itself is not either a test_* function or also a fixture? known examples that can use fixtures: 1) def ...
KenB's user avatar
  • 181
18 votes
5 answers
13k views

Automatic associations in ruby on rails fixtures

As described in this article, I am using automatic associations in fixtures. For example, if a region object has a country id, instead of doing "country_id": 1, I do "country": "USA". "USA" is a ...
Tony's user avatar
  • 18.9k
18 votes
7 answers
12k views

factory_girl + rspec doesn't seem to roll back changes after each example

Similar to the problem described here: http://rpheath.com/posts/411-how-to-use-factory-girl-with-rspec in Short (shorten'd code): spec_helper: config.use_transactional_fixtures = true config....
Rex's user avatar
  • 181

1
2 3 4 5
35