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

1601 questions
538
votes
6 answers

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 inject into my tests. I have two questions: Is this…
Aviv Cohn
  • 15,543
  • 25
  • 68
  • 131
337
votes
6 answers

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
  • 5,328
  • 2
  • 16
  • 34
241
votes
10 answers

Pass a parameter to a fixture function

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 test_... files I want to reuse the tester object…
maggie
  • 3,935
  • 3
  • 27
  • 31
122
votes
17 answers

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 > fixture.json but I kept getting missing foreign key…
gerdemb
  • 11,275
  • 17
  • 65
  • 73
91
votes
6 answers

How to create a fixture file

I want to create a fixture file in my Django project. How can I do this?
Viktor Apoyan
  • 10,655
  • 22
  • 85
  • 147
68
votes
7 answers

@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 -------test_test.py in func.py: def a(): …
Hello lad
  • 17,344
  • 46
  • 127
  • 200
68
votes
4 answers

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
  • 148,955
  • 89
  • 346
  • 502
61
votes
4 answers

Can I 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.fixture def passenger(): return…
pyzzled
  • 611
  • 1
  • 5
  • 4
60
votes
5 answers

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 do expect tests to send emails, I want to use a…
ThiefMaster
  • 310,957
  • 84
  • 592
  • 636
58
votes
4 answers

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 them. I implemented this with a post_save…
poswald
  • 1,755
  • 1
  • 11
  • 11
57
votes
9 answers

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, because it looks like loading only the fixture for…
gleb.pitsevich
  • 1,269
  • 2
  • 12
  • 18
50
votes
6 answers

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 doing User.new(:name = "John", :email = "..") each…
Patrick Pruneau
  • 669
  • 3
  • 7
  • 14
47
votes
3 answers

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 folder. Why is sonoftest.py not searched? #…
Dave
  • 4,184
  • 8
  • 40
  • 46
42
votes
2 answers

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 exactly is the difference. which should I use, in cases…
Gaurang Shah
  • 11,764
  • 9
  • 74
  • 137
42
votes
10 answers

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 tables with lookup data. When I create a Cart with two…
Mark Eric
  • 753
  • 1
  • 7
  • 14
1
2 3
99 100