接口自动化中依赖数据的存储方式(列举2种)

1.以写入文件的方式来存储

  • 先创建一个ini 文件用来保存依赖数据,用到的库为configparser,使用之前让我们先来看一下原生库对于ini的操作方法吧~,在set 方法中有3个参数,为了方便理解,我建了一个ini 的文件,如图所示:
    def set(self, section, option, value=None):
         """Set an option.  Extends RawConfigParser.set by validating type and
         interpolation syntax on the value."""
         self._validate_value_types(option=option, value=value)
         super().set(section, option, value)

  • 了解主要参数之后,我们创建一个操作ini的class,主要包括setValue(存),getValue(取)的方法。:
    class ConfigReader:
    
        def __init__(self,path=run_results_ini_file):
            self.path = path
            self.CReader=configparser.ConfigParser()
            self.CReader.read(path,encoding='utf-8-sig')
            self.CReader.get()
    
        def __new__(cls, *args, **kwargs):
            if not hasattr(ConfigReader, "_instance"):
                ConfigReader._instance = object.__new__(cls)
            return ConfigReader._instance
    
        def getSection(self):
            return self.CReader.sections()
    
        def getDict(self,section):
            s={}
            for k,v in self.CReader.items(section):
                s[k]=v
            return s
    
        def setValue(self,section,option,value):
            self.CReader.set(section,option,value)
            self.CReader.write(open(self.path,"r+"))
    
        def  getValue(self,section,key):
            for k, v in self.CReader.items(section):
                if k==key:
                    return v

测试一下,这样一个以存文件形式的依赖存储方式就完成了,个人觉得这种方法适合刚接触的python学习的新手,主要是可以练练手啦~那有没有更简单的方法呢?

ini = ConfigReader()
ini.setValue('depence','token1','45646asdsad4565')
print(ini.getValue('depence','token1')) #输出45646asdsad4565 

2.以动态添加类属性的方法存储

  • 新建一个py,创建一个依赖类,什么?这么简单的类?哈哈哈就是这么简单~
    class DependData:
        pass
  • 我们用setattr给依赖类添加类属性,并打印,成功添加token~
    setattr(DependData,'token','123')
    print(DependData.__dict__) #{'__module__': '__main__', '__dict__': <attribute '__dict__' of 'DependData' objects>, '__weakref__': <attribute '__weakref__' of 'DependData' objects>, '__doc__': None, 'token': '123'}
  •  那么怎么把依赖属性提取出来呢?getattr 登场咯~
    getattr(DependData,'token')#123

     

    总结: 两种方法个人更倾向于以动态添加类属性的方法去储存,相较于储存到文件,性能上节省了对于文件io的时间,使用上也更加方便,更容易理解~

 

 

 

21,559 次浏览

“接口自动化中依赖数据的存储方式(列举2种)”的2,482个回复

  1. When someone writes an paragraph he/she maintains the
    idea of a user in his/her mind that how a
    user can understand it. Thus that’s why this paragraph is perfect.
    Thanks!

  2. Today, while I was at work, my sister stole my apple ipad and tested to see
    if it can survive a 25 foot drop, just so she can be
    a youtube sensation. My iPad is now destroyed and she
    has 83 views. I know this is totally off topic but I had to share it with someone!

  3. Superb blog you have here but I was curious about if you knew of any user discussion forums that
    cover the same topics talked about here? I’d really love to be a part of group where I can get feedback from
    other experienced people that share the same interest.
    If you have any suggestions, please let me know. Appreciate it!

  4. I’m really impressed with your writing skills as well
    as with the layout on your weblog. Is this a paid theme or did you customize it yourself?
    Anyway keep up the excellent quality writing, it’s rare to see a nice blog like this
    one these days.

  5. That color looks perfect on you.
    You are an excellent friend.
    I am really glad we met.
    You just glow.
    You are the most perfect you there is.
    You are one of the bravest people I know.
    You are so 오피
    ; I always believe what you say.
    You inspire me.
    Your inside is even more beautiful than your outside.
    Everything seems brighter when you are around.
    I am a better person because of you.

  6. Definitely imagine that which you said. Your favourite
    reason seemed to be at the web the easiest thing to
    bear in mind of. I say to you, I definitely get annoyed at the same time as folks consider worries that they just do not know about.
    You managed to hit the nail upon the highest as smartly as outlined out파워볼분석
    the entire thing without having side effect , people
    can take a signal. Will likely be back to get more. Thanks

  7. Fantastic goods from you, man. I have consider your stuff previous to and you’re just too excellent.
    I actually like what you’ve got right here, certainly like what you’re
    saying and the way in which by which you are saying it. You make it
    enjoyable and you continue to care for to keep it sensible.
    I can’t wait to read much more from you. This is actually a great web site.

  8. It’s appropriate time to make some plans for the future and it’s time to be happy.
    I’ve read this post and if I could I desire to suggest you some interesting things or tips.
    Maybe you could write next articles referring to this article.

    I wish to read more things about it!

  9. I’m really enjoying the design and layout of your site.

    It’s a very easy on the eyes which makes it much more pleasant for me to come here and visit more
    often. Did you hire out a designer to create your theme?
    Fantastic work!

  10. [url=http://celebrexcelecoxib.com/]celebrex 100 mg tablets[/url] [url=http://silagra24.com/]silagra[/url] [url=http://tadalafilsale.com/]tadalafil 20 mg[/url] [url=http://amoxicillinz.com/]buy amoxicillin online[/url] [url=http://avanatop.com/]buy avana 50 mg[/url] [url=http://priligytab.com/]priligy buy online[/url] [url=http://erythromycinz.com/]buy erythromycin[/url] [url=http://dapoxetinetabs.com/]buy dapoxetine[/url]

  11. Hi excellent website! Does running a blog similar to this require a large amount of work?
    I’ve virtually no knowledge of coding however I was hoping to start my own blog in the near future.
    Anyway, should you have any recommendations or
    techniques for new blog owners please share.
    I know this is off topic but I simply had to ask. Thank you!

  12. I’ve been surfing online more than three hours today, yet I never found
    any interesting article like yours. It is pretty worth enough for me.

    Personally, if all site owners and bloggers made good content as you did, the web will
    be much more useful than ever before.

  13. Hi! Do you know if they make any plugins to help
    with Search Engine Optimization? I’m trying to get my blog to rank for
    some targeted keywords but I’m not seeing very good gains.
    If you know of any please share. Kudos!

  14. You really make it appear really easy together with your presentation however I to find this
    matter to be really something which I feel I would by
    no means understand. It sort of feels too complex and extremely large for me.
    I’m looking ahead for your subsequent post, I will try to get the dangle
    of it!

  15. [url=https://kamagra911.com/]cheap kamagra pills uk[/url] [url=https://cymbaltarx.com/]cymbalta pills for sale[/url] [url=https://clomid150.com/]clomid medication south africa[/url] [url=https://lipitor2020.com/]lipitor copay[/url] [url=https://clonidinenorx.com/]clonidine online canada[/url] [url=https://motilium10mg.com/]motilium nz[/url] [url=https://chloroquineav.com/]chloroquine malaria prophylaxis[/url] [url=https://xenicaltabs.com/]xenical nz pharmacy[/url] [url=https://augmentin875.com/]augmentin 500 online[/url] [url=https://nolvadex10.com/]buy nolvadex australia[/url]

  16. [url=http://sildalistab.com/]sildalis 100mg 20mg[/url] [url=http://accutanisotretinoin.com/]where can you get accutane[/url] [url=http://cytotec100.com/]can you buy cytotec over the counter[/url] [url=http://ivermectin3.com/]ivermectin gel[/url] [url=http://motilium10mg.com/]motilium 10mg canada[/url] [url=http://chloroquineav.com/]aralen generic[/url]

  17. This design is spectacular! You certainly know how to keep a reader entertained.
    Between your wit and your videos, I was almost moved to start my own blog
    (well, almost…HaHa!) Great job. I really enjoyed what you had to say,
    and more than that, how you presented it. Too cool!
    adreamoftrains best hosting

  18. Someone necessarily help to make critically articles I’d state.
    That is the first time I frequented your web page
    and so far? I amazed with the analysis you made to create
    this actual put up incredible. Great activity!

  19. To skin of one’s teeth decontamination between my life up in the crown on the urinary side blocking my lung, and in the in days gone by I was habituated to in red them at near transfusion replacement them whirl unrecognized and cardiac the omission of as chest. slots online golden nugget online casino

  20. [url=http://prednisonesr.com/]prednisone canada pharmacy[/url] [url=http://lexaporo.com/]no prescription cipralex[/url] [url=http://clomid150.com/]where to get clomid online[/url] [url=http://prozacflx.com/]how to buy prozac without prescription[/url] [url=http://priligydapoxetin.com/]priligy australia cost[/url] [url=http://seroquel50.com/]generic for seroquel[/url] [url=http://fluoxetinetb.com/]fluoxetine cost 20mg[/url] [url=http://ampicillin24.com/]ampicillin cost[/url]

  21. [url=https://finasteridealop.com/]finasteride drug[/url] [url=https://medrol80.com/]medrol 500 mg tablet[/url] [url=https://silagratab.com/]silagra pills in india[/url] [url=https://acyclovirzov.com/]aciclovir tablets[/url] [url=https://cymbaltarx.com/]cymbalta prescription coupon[/url]

  22. [url=https://finpecia911.com/]finpecia tablets online[/url] [url=https://malegra.us.org/]malegra fxt online[/url] [url=https://medrol80.com/]medrol 16 mg buy[/url] [url=https://hydroxychloroquinecv.com/]buy plaquenil in india[/url]

  23. [url=https://cephalexin911.com/]buy cephalexin 500mg without prescription[/url] [url=https://phenergan125.com/]phenergan pill cost[/url] [url=https://xenicaltabs.com/]buy over the counter xenical[/url] [url=https://backtrim.com/]bactrim sulfamethoxazole[/url]

  24. [url=https://vardenafilxr.com/]vardenafil without prescription[/url] [url=https://robaxin24.com/]robaxin 750 mg tablet[/url] [url=https://lipitor2020.com/]lipitor price uk[/url] [url=https://vermox100.com/]order vermox online[/url] [url=https://anafranilmed.com/]anafranil price in us[/url]

  25. Hey there! I understand this is somewhat off-topic however I needed
    to ask. Does building a well-established blog such as yours take a lot of work?

    I’m completely new to writing a blog but I do write in my diary on a daily basis.
    I’d like to start a blog so I can easily share my
    own experience and thoughts online. Please let me know if you have any
    kind of suggestions or tips for brand new aspiring bloggers.
    Thankyou!

  26. Способ приготовления:
    Сливочный сыр и творог протрите через сито по отдельности, посолите по вкусу, соедините и протрите массу еще раз. Влейте сливки, помешивая, затем взбейте и переложите в дуршлаг, выложенный изнутри льняной салфеткой. Дуршлаг поставьте на кастрюлю и вынесите в холодное место на 3-4 часа.
    При подаче готовый сыр осторожно переверните на блюдо, посыпьте сахарной пудрой и оформите ягодами клубники.
    источник https://rassadaklubniki.ru/tvorojnii-sir-s-klubnikoi/

  27. I seriously love your blog.. Pleasant colors & theme.
    Did you develop this website yourself? Please reply back as I’m planning to create my
    very own site and want to learn where you got this from or what the theme
    is named. Thanks!

  28. I have to thank you for the efforts you have put in penning this website.
    I am hoping to check out the same high-grade content from you in the future as
    well. In fact, your creative writing abilities has inspired me to get my very own website now 😉

  29. Doxycycline
    Side effects are quite possible if you are using Doxycycline. It is ideal to buy Doxycycline from trusted resources that sell good quality drug. However, even with most good quality drugs, you may find some common side effects such as nausea, diarrhea, indigestion, vomiting, allergy and appetite loss.
    information https://doxycycline2020.top/

  30. Save me from remaking all these from the beginning please :/

    [url]https://winkel14bitsch.webgarden.cz/rubriky/winkel14bitsch-s-blog/unnamed-2[/url]

  31. I’ve tried just about everything have you got any ideas on how to do it correctly?:c

    [url]https://v.gd/nP58XT[/url]
    [url]https://seller.ae/user/profile/94430[/url]
    [url]https://issuu.com/wittgarcia5[/url]
    [url]https://www.blackplanet.com/clinestanley33/message/21698274[/url]
    [url]https://www.ted.com/profiles/22770812[/url]

  32. [url=https://colchicine5.com/]colchicine generic pharmacy[/url] [url=https://cleocing.com/]where to buy cleocin cream[/url] [url=https://dapoxetine911.com/]dapoxetine uk cost[/url] [url=https://toradoliv.com/]toradol 100mg[/url] [url=https://kamagra911.com/]kamagra singapore[/url] [url=https://cymbaltarx.com/]cymbalta 20mg[/url] [url=https://chloroquineav.com/]aralen australia[/url] [url=https://lisinopril125.com/]cost of lisinopril 30 mg[/url] [url=https://anafranilmed.com/]anafranil for ocd[/url] [url=https://fluoxetinetb.com/]fluoxetine 20 mg uk[/url] [url=https://glucophagge.com/]where to buy glucophage online[/url] [url=https://estrace2.com/]estrace rx[/url] [url=https://inderal.us.com/]inderal medication[/url] [url=https://tetracyclinecaps.com/]tetracycline over the counter[/url] [url=https://tadalafilm.com/]tadalafil 47[/url] [url=https://zoloft360.com/]2 zoloft[/url] [url=https://sildalistab.com/]sildalis without prescription[/url] [url=https://buspar24.com/]otc buspar[/url] [url=https://stratterra.com/]how much is strattera in canada[/url] [url=https://priligydapoxetin.com/]where to buy priligy in usa[/url]

  33. Wrist and varicella of the mechanically ventilated; resolute stature and living with for both the synergistic network and the online cialis known; survival to relief the specific of all patients to contrive circa and to get up with a effective of aspiration from another unsusceptible; and, independently, of for pituitary the pleural sclerosis of resilience considerations who are not needed to masterfulness is. sildenafil dosage Fsyyhw omixab

  34. [url=http://dipyridamol.com/]cheapest dipyridamole prices[/url] [url=http://trazodone911.com/]trazodone price australia[/url] [url=http://colchicine5.com/]colchicine otc[/url] [url=http://lipitor2020.com/]lipitor 40 mg tablet[/url] [url=http://inderal.us.com/]inderal 30 mg[/url] [url=http://ventolin24.com/]ventolin cost australia[/url] [url=http://augmentin875.com/]how much is augmentin 875[/url]

  35. Its like you read my mind! You seem to understand so much approximately this,
    like you wrote the book in it or something. I feel that you could
    do with a few % to power the message home a little bit, but
    instead of that, this is fantastic blog. A fantastic read.

    I’ll definitely be back.

  36. Thanks for a marvelous posting! I seriously enjoyed reading it, you are
    a great author. I will always bookmark your blog
    and may come back sometime soon. I want to encourage
    yourself to continue your great posts, have a nice evening!

  37. Hi, i believe that i noticed you visited my weblog so i came to go back the favor?.I’m attempting to find issues to improve my
    site!I guess its good enough to make use of some of your concepts!!
    y2yxvvfw cheap flights