fixtures

Accessing test file name from conftest.py

做~自己de王妃 提交于 2019-12-02 06:52:15
问题 What I'm trying to do I'm writing a small framework in python using pytest, and as part of the teardown I am taking a screenshot. Now, I want that screenshot to be named according to the running test, not conftest.py So, for example, my code right now is: driver.save_screenshot(os.path.basename(__file__)+'.png') The problem This prints the name "conftest.py". I want to print the calling test name if possible. I am guessing using requests? 回答1: You can access the current file path via request

Accessing test file name from conftest.py

大兔子大兔子 提交于 2019-12-02 06:40:22
What I'm trying to do I'm writing a small framework in python using pytest, and as part of the teardown I am taking a screenshot. Now, I want that screenshot to be named according to the running test, not conftest.py So, for example, my code right now is: driver.save_screenshot(os.path.basename(__file__)+'.png') The problem This prints the name "conftest.py". I want to print the calling test name if possible. I am guessing using requests? You can access the current file path via request.node.fspath . Example: # conftest.py import pytest @pytest.fixture def currpath(request): return str(request

Ruby: How do you configure an enum in a fixture?

烈酒焚心 提交于 2019-12-01 17:34:11
问题 Given this class: class User < ActiveRecord::Base enum permission: { permission_user: 1, permission_staff: 2, permission_manager: 3, permission_admin: 4, permission_super_admin: 5 } I want to create a fixture that looks like this: testuser1: id: 1 username: sam permission: :permission_staff I've tried a number of variations of syntax, but haven't found something that works. the resulting user.permission is either nil or 0. I know that enum is relatively recent addition. Can this be done? 回答1:

Pytest use same fixture twice in one function

非 Y 不嫁゛ 提交于 2019-12-01 15:07:26
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? from test.fixtures import login class TestGroups(object): def test_get_own_only(self, login, login): pass 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])

Pytest use same fixture twice in one function

China☆狼群 提交于 2019-12-01 14:40:10
问题 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? from test.fixtures import login class TestGroups(object): def test_get_own_only(self, login, login): pass 回答1: 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

Does a model's save() method get called when using loaddata for fixtures?

怎甘沉沦 提交于 2019-12-01 11:24:55
I'm trying to generate an automatic slug for a model whenever it is empty, from another field. This is the code: class Position(RichText): name = models.CharField(max_length=200) slug = models.SlugField(null=True) def position_description(self): return self.content def __unicode__(self): return self.name def save(self, *args, **kwargs): if not self.slug: self.slug = slugify(self.name) super(Position, self).save(*args, **kwargs) When I load initial fixtures with loaddata, it seems the save() method is never triggered. Is this normal behavior? How can I catch fixtures too? This is normal

Django Natural Key for Fixtures Give Deserialization Error

情到浓时终转凉″ 提交于 2019-12-01 08:52:11
I've seen a few similar questions to this on SO, but none seem to answer my particular problem. I'm new to Django and was guiding myself by the instructions at this page to allow myself to use natural keys to load fixtures. Nevertheless, I'm getting Deserialization errors because Django wants an integer for a foreign key and can't seem to map my natural key to an integer primary key as is noted in the instructions. Specifically, my relevant models code is: class GraphTypeManager(models.Manager): def get_by_natural_key(self, type): return self.get(type=type) class GraphType(models.Model): type

Does a model's save() method get called when using loaddata for fixtures?

帅比萌擦擦* 提交于 2019-12-01 08:25:23
问题 I'm trying to generate an automatic slug for a model whenever it is empty, from another field. This is the code: class Position(RichText): name = models.CharField(max_length=200) slug = models.SlugField(null=True) def position_description(self): return self.content def __unicode__(self): return self.name def save(self, *args, **kwargs): if not self.slug: self.slug = slugify(self.name) super(Position, self).save(*args, **kwargs) When I load initial fixtures with loaddata, it seems the save()

undefined method `users' for Tests

谁都会走 提交于 2019-12-01 04:38:34
问题 I'm trying to write a simple test but my application is not detecting 'users' keyword when I'm using it in my Test functions: post_controller_test.rb : require 'test_helper' class PostsControllerTest < ActionController::TestCase # test "the truth" do # assert true # end test "should fetch facebook post" do sign_in users(:one) get(:save_posts_from_facebook_page,{'id'=>'my_id'},{'access_token'=>Rails.application.secrets.fb_access_token}) assert_response :success end end test_helper.rb : ENV[

Convert fixtures into Factory Girl in Rails

回眸只為那壹抹淺笑 提交于 2019-11-30 22:04:09
I'd like to migrate my fixtures to "Factory Girl" in Rails. Is there any easy way to convert all yml files in a factories.rb file? I am assuming what you are looking to do is find a script which will look through your models and generate the factories for them. I tried this once (with something other than factory_girl) and found it full of bad data. I would suggest that you slowly transition to using factories. As you write new tests or update old ones, create the necessary factories. As time goes by, if you have the time and energy you can then choose an individual test case and replace all