Questions tagged [fixture]

Fixed state(s) for software under test, also known as text context

In software testing, a test fixture is a fixed state of the software under test used as a baseline for running tests; also known as the test context. It may also refer to the actions performed in order to bring the system into such a state.

It is often used in and .

Examples of fixtures:

  • Loading a with a specific, known set of
  • Erasing a hard disk and installing a known clean operating system installation
  • Copying a specific known set of files
  • Preparation of input data and set-up/creation of fake or objects
  • Software used to systematically run reproducible tests on a piece of software under test is known as a test; part of its job is to set up suitable test fixtures.

Source

132 questions
94
votes
4 answers

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 @pytest.fixture def my_wallet(): '''Returns a…
oglop
  • 1,175
  • 1
  • 9
  • 15
85
votes
1 answer

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 "<%= variable %>" (un-interpolated). How do I escape the…
Daniel
  • 7,006
  • 7
  • 43
  • 49
30
votes
4 answers

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
  • 2,673
  • 3
  • 30
  • 37
28
votes
1 answer

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 some more custom stuff for that user. As far as I…
numegil
  • 1,916
  • 7
  • 26
  • 38
22
votes
4 answers

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 foo return __make_foo What are the…
Ben Reed
  • 824
  • 1
  • 8
  • 26
16
votes
7 answers

How to load sql fixture in Django for User model?

Does anyone knows how to load initial data for auth.User using sql fixtures? For my models, I just got have a < modelname >.sql file in a folder named sql that syncdb does it's job beautifully. But I have no clue how to do it for the auth.User…
aldux
  • 2,774
  • 2
  • 25
  • 36
11
votes
2 answers

How do you put a file in a fixture in Django?

I can easily fill the field of a FileField or ImageField in a Django fixture with a file name, but that file doesn't exist and when I try to test my application it fails because that file doesn't exist. How do I correctly populate a FileField or…
Pablo Fernandez
  • 279,434
  • 135
  • 377
  • 622
11
votes
5 answers

Any way to pass parameters into pytest fixture?

I am not talking about the Parameterizing a fixture feature that allows a fixture to be run multiple times for a hard-coded set of parameters. I have a LOT of tests that follow a pattern like: httpcode = 401 # this is different per call message =…
Jason Antman
  • 2,620
  • 2
  • 24
  • 26
8
votes
1 answer

NUnit sometimes ends with "unable to locate fixture"

The NUnit-console 2.6.3 sometimes prints out the following error message instead of running tests. Here is excerpt from my Jenkins test build logs: 00:05:02.982 Process 'nunit-console-x86' [PID 3684] has begun profiling. 00:05:03.698 NUnit-Console…
krzysiek_w
  • 81
  • 5
7
votes
1 answer

Getting the primary key (id) in fixture (Python, SQLAlchemy)

I'm using fixture to test a Pylons app, but I stumbled upon a problem. Let's say I have such data set: class CompanyData(DataSet): class test_company: company_full_name = u'Firma Tęst' company_short_name = u'TęstCo' class…
Juliusz Gonera
  • 4,658
  • 5
  • 32
  • 35
6
votes
4 answers

boost-test initialization for each suite (not case)

I need to init some variables, which are "global" inside a BOOST_AUTO_TEST_SUITE so their constructors will be called when the suite starts and their destructors will be called right after the last corresponding BOOST_AUTO_TEST_CASE is finished does…
Alek86
  • 1,489
  • 3
  • 17
  • 26
6
votes
3 answers

cannot dump data by using python ./manage.py dumpdata app

I created an app in a Django project. For testing purpose, I would like to create fixture files. I found that I can dump my database in order to create fixture automatically if it already has data. I want to use a fixture, so I used the command…
Fon
  • 299
  • 1
  • 3
  • 16
6
votes
4 answers

initial_data fixture management in django

The django projet I'm working on has a ton of initial_data fixture data. It seems by default the only way to have data load automatically is to have a file in your app folder called fixtures, and the file needs to be named initial_data.ext (ext…
priestc
  • 33,060
  • 24
  • 83
  • 117
6
votes
1 answer

In pytest, how to make sure the module level fixture is called before class level

My pytest is old(version 2.8.3). pytestmark = pytest.mark.usefixtures("module_level") @pytest.fixture(scope='module') def module_level(request): print("module start") def fin(): print("module end") …
Hao Shen
  • 2,605
  • 3
  • 37
  • 68
6
votes
1 answer

Difference Stub Fixture

I am learning codeception and I wonder what is the difference between stubs and fixtures. Both help me to load well-defined data and kepp tessts simple. But when do I use \Codeception\Util\Stub and when do I use \Codeception\Util\Fixtures
astridx
  • 6,581
  • 4
  • 17
  • 35
1
2 3
8 9