Merken

Advanced Uses of py.test Fixtures

Zitierlink des Filmsegments
Embed Code

Automatisierte Medienanalyse

Beta
Erkannte Entitäten
Sprachtranskript
please welcome farmers few and government and so yeah
advantages and what it does to but this fix is sort of a quite
unique and powerful feature in them invited test and they allow you demonstrate that allow you to to great efficiency using dependency injection and a kind of breaks and kind of isolated and and and quite composable sense appeal to you and so I'll try and get go through like he and I have been using by and being contributed for for a few years now and so basically on based on like that experience of of trying build up some some more of the and interesting things and to to build a big test that we find useful building a bit testing and I'm going to assume some knowledge about how test itself and based on that and then you get the basic idea of how features such as having been injection so that would and that's a very quick reminded me of that and so so fixtures is basically service on a test function that can request affects about by just take the parameter net and named parameters and the named parameter and will then be looked up by hand to function that's decorated this fiction and market and which is dysfunctional gene's value and the value is then injected by contrast into and you test functions you can create fiction different levels in the neuron the files so if you do in class the the visibility and members of the class and so that sort of very very quickly they on to basic and so the 1st thing to to start and sort of extend standing up to them caching and what you fixtures and this sort of and so that basically but by by simply giving another keyword arguments due to this and the fiction decorated and you can change the scope that the lifetime of a flat how long that that picture lives and normally it's being if if you don't provide expertise that people just the phone to tone down straight away after after the test function is run and that you can change scopes into like accession scope and just like models spoken cost size functions and and then and that basically means that you you only and call color function once for the scope so in the in this example the we got to different spoke protons 1 functions scope and 1 session scope and and and we got to test using both of these this is fairly contrived against but if you're part and in the output using minus X here which stands stops the and and make sure that the print statements are putting my in my test actually
can get showing up because only by the test set and captured at and only show in case of failures but with my ancestors and you can clearly see the order that things happened
here so so this session so that happens 1st and then the fact that happens then the daughter and which is spatially detested been around and then the function for and finalize instead on kind happens and and then the hands again and so agency how'd caching so the works so if you got expensive and fixtures that you don't want to recreate the whole time like the populated database to schema something great web browsers so all those things you
know this is a very common thing to start confusing 10 yet and yet so the variable scopes that and next on is sort of fixtures can just and can be used in in all the pictures not just in test functions and that
makes it really composable because it it means you can have have and so so in this example that you know operating in at the database collection fiction and that might be used to some test directly and that and and for example if this is a functional tests and 1 frontal test new you need stand on the table to be there something I can just belong on this existing fiction and you can puzzle them together in that manner and 1 of the interior and request and fiction as being regret and cost there is it's a it's a major finalizes due 2 places it's probably already there is essentially no more than just another fixture in pilot tests
that building 1 that's provided set so that kind of thing that happens quite similar to and they this function here has since simply uses the and that the the latest 1 that that DB tables fiction but it could have been
using birth as well so that needed because of some for some reason this there's
no reason not not to and use and combining them with and another thing you can do in another fiction and said so normally when when you're interested in biphasic and not just want to get this test something for for whatever reason we can also do is based on uh triggered is from inside a fixture for us and basically so and that if if you do that means that any test that will be requested you will be using the fixture will automatically be skipped in instead of and so you can make this depends on something else and so in this this this example is something that we use quite a commonly when we connect to remote service of things and so so basically for 1st tried to develop running it from on the on the and the hundreds if not see very often that structure I iconic into several that networks of things but you know it's neither dead and whatever and let let's constituents and that combining this with the session scope for example means that you don't keep doing that again and again and because that might be slow operation something and then o thing to note here is that when you call skip like this and we will with a message that is the basic tightest to escape will raise an exception in in your code so for the control flow of of of the fiction you have to realize when you stick by the tests of and still get you basically raise an exception empire tests and of that and the no no code will be executed after the 2nd and just like you got just skip this part of still fail and will do exactly the same but fail the test for whatever reason if you want to do that and and this is sort of a and sort of such slide size that and talking about introducing lots of that and hopefully you've already variety constant multiplied test is very flexible much interesting so it's basically just a decorator lattice of market told and then a name you choose yourself so thing and you can just applied the greater to to test functions and then you test function will be marked and down its own isn't yeah doesn't provide you very much you can so the views on the command line to select you mark and but it is doesn't provide that and wanting to all all get acted on the next slide basically but 1 thing to note here is that you can the mark multiple and marxist economic supply multiple MaxEnt onto a single test function internet and then another thing is that because Marx's of flexible this sort of that they're they're allowed to be made and have available on the fly basically so and what 1 sort of sites that the side effect of that is that if you make a typo in a market you may not notice that animate kind of regulator and that's why sort of have 2 kinds of people I think and some people like me prefer to use and demands Maastricht option to buy the test so that you get caught out and you have to and basically declare you marks the front and and you get then notified of any mistakes you during and and the obvious way to just always enforce that this is right in the configuration files so that's basically the example of how you write in the compressed file and model specially always the command line option when you invoke at and you declared markets in this example now if if you try to run this time it would fail because only 1 of the markers has been declared and so so an Marcus but the so so much markers that like you know used by applicants it's surprised at this well if you legends them that
don't make use of that I'm on my way to make use of inside readily detected in your pictures and so In hated test function wants clients and and it's a little bit contrived 1 moment doesn't quite work like that but almost without but so basically in the in the among client and and we're really glad we also declared that democracy that declaring did and database to put into your eyes to be used as a connection time and then when you actually look in the fixture you can't but basically what it tries to do is like that tries to look if there is that is there market yes and then I'm going to use that as the database name if and if not just the use of the full data 1st name and great client return and I meant to actually get the this Bismarck information user request of nodes and such a requested node itself this is think that that is that the best note which is a internal test representation of the text itself so object we will actually the function that you're actually testing and and and it has it has quite a quite a few methods such look it up in in the documentation of the bottom-up and the documented and they get marker is is basically how how you get all the market and the only thing is like the it and if you get this this sort marker objects and in the case so so either you get as part the from the if you get normal and we just use the for 1 year they in the case of a marker object the way it passes the status you see that the mark that takes an argument here and the way passes on the arguments that you've specified it just passes on hazardous KW arcs and attributes market objects that which is listed the dictionary and which is a very common representation but the problem with that is that it's it's not how and by signature such so that so I use little and help function which like oncology from in this case and and it doesn't do anything useful then it uses the Python itself to pass a signature for me so it means that if someone an effective or the decorated differently among would it be the equals uses it would still work because to by and by things that citizen who just signature and then return and my database that's so that's how I white called that functionalism starts and KW so that's sort of a little trick to to to get native fight signatures working and I have to add that into the future that emerging probably 1 of the next releases and that there is going to be a slightly different way or a new way to use the full declaring markets which will get around this this little hockey as signature passing stuff so so that that would improve but this this is sort of the way we do things got units that's financial and another and commonly used in its and features can also be automatically especially so normally fixtures and are always depends injected so you test which to request that the fixture by naming what wants
to have and but and it's sort sometimes that and that might not not be and not be suitable so so this is to use she was true an argument to the fiction decorated in that case is the base of the call for every and test and test functions and automatically whether it be requested or not and so this is kind of a lot closer if you used to the end you just kind of weird things to to set up and down because that just call every single time and 1 at 1 of the nice things here well that can and combine it with the script scope argument as well so if you do this and see the great cannot fiction within the scope the scope of this section that basically means you you only yeah only achieve right beginning to test session you will be doing some and at the end you'll be doing something that and did obvious fiction and and in this case I sort of is it written on them with an underscore so sort of indicating that you know I don't expect it to be used immediately with timbre there's nothing stopping you from there's nothing stopping you from returning a value as well and explicitly requested so if someone actually request you can just mix them and mix those 2 together as well and so in in the in this case is also the and use it to greatest there's kind of questions skipping logic and for something that's only stands 1st to work on more minutes and this various ways of doing I guess that some examples of then
parameterized fiction fiction is sort of another variant and powerful and the feature can do and fiction and so in this example sort of and we have a
test function from the the 1st
test function that test that did and with which we just use this and basically you're right interconnected databases and the the problem here is you know 1 ensure that whatever this well to oppose this growth or pollen and ask you like for example at the same time and so is that had to write the test so alright so that's different fiction something you can basically parameterized you're you're you fix you itself says and by parameterizing this fiction and pilot test will create will call my best friend from 3 times once we did meet each parameter and the way you know which prompts so so that and the arguments in the and the list and the parents keyword infection decorated can can be anything it's it's up to you so you can use Direct values that you want to all and in this case we using simple strings which then I'll probably use to but in a statement or something and that you get access to the prompt to being passed in by this request so parameters and attributes going on on the fiction and that's how we system and and so the building on top of that is if you have want multiple and fixtures with parameters you can combine images that what the loss function thus and so so in this case because both perhaps less but fixtures are parameterized by the test will basically call last functions 6 times because it request both of these and you'll get each combination tested automatically so in this case of the example and suggest that I want to test the connection of word accuracy for insects and but you automatically get all combinations of of you fixtures and the build some sort of society building on top of that is so sort of you may you can actually sort of mark
your parameters again in in in your and parameterize this so you can and if there is picture so in this example I I don't assume that have every developer has has the oracle and the bigger I installed and so so I just you know tribal Oracle if that if not and and is willing to use 2 things at once as a result of that so we've already seen using markers especially so this is by this margin skip if building market upon that provides and a set of kind using directly on something I just assign to a viable and that's just to make my life to the short electron basically or maybe I want to use more than 1 source into me so you can just assign marked a viable and then you have that marker object that is genes later on and in this case I apply basically only because it my ground trees is not not functions are countries decorating isn't just money applied at all onto my parameter mn and it means that if I don't have organized all this despite that the test function should be parameterized on only 1 version of them will be run and the 2nd listed this is sort of an example and taken from the wild roughly from an earlier version of the widest general but it shows kind of how you can see you they basically that the thing here is the request of fiction and some and part of the fixtures and and it allows you to see all the other features that are being you requested by by the current test functions so you can in in this case and just stopping and Due to fictions that our army mutually exclusive being use the same by by simply calling pipe and it that I detect the case and that you can sort of it into into what the test function asking and so that we have have a have a look at the bill of fixes around and which sometimes could be useful thing then sort of a very and sort of and steps either yes
and you've probably if you've been using part of test and 16 this contest apply files that so this is sort of typical and directory like you'll you'll get an example of a constant supply so see you can declare fiction there and then you'll see them in the entire directory basically and the constant supplies basically from by pilot tests and point of view it's just another plug-in just like any other part of test that you install but it's a and it's applied projects kind of and essentially when when you start building a big test you going to be building project within kind thing and applicants will produce it is systems so basically in your blood and you you find function would would you look at pilot test at at certain times call these holds that if if you define 1 and this is just a few common ones and that's a much longer list and look mentation the analysis be showing like basically that the adults and 1 here which sort of and adding new command
line option the possible object you get In that work especially just
past and command-line parsing and seeking just use that documentation to to at your options here and here adding an option saying and so basically the idea here is that if if mindful for my script votes by test was and all the beaches Boston that minus minus your options are I know as much as to discern and and just very quickly you can get to it and to command line options but from inside features as well as test functions again invited to request an object which has a conflict and context completion and representation so you can get access to that command options the configuration functions in and and basically the boat request the confirmation of pi test configuration of the same in an instance the different ways of getting to them and and those 2 and you call combining all that together sort of and can this is sort of expanding on an example I used earlier and he says so again and so so here I have this external services this is a already service and that that before I checked I was on my developers left opposite my and it is in the office of something but and and hours just skipping those but in this case and but by using requested confident checking option I can make sure that when I'm running my of it really is going to execute them and if not I actually get heart failure so I can see success so it is every standard on just from the start stop testing as part of my chest CT and so the things and so that's that's yeah another thing that we use quite a lot and this this and embryonic the that yeah that's basically what we have so far but
yeah than through the snow and was used in a few you which is the for treatment is it worth the using the following
problem was minus the sum and so we the all the things that case and so and this was so OK so the question is what I showed how to get the names that deal the fiction names of the but of the test function there is also a way of getting the value of that and the other is sort of 2 fold and definitely yes obviously by simply requesting himself and but that's not dynamic and there is an escape hatch to to do that dynamical although it's discouraged because and so basically on on the requests and fixtures of there's a from Prague values and call which you can and used to call the value and the Internet chances so that's how you can get to the end but generally that's discouraged because if you use that form if you use 1 that's already requested this probably OK refused on 1 that hasn't been requested yet and quite a sort of loses its fuel and all the combinations of all things and and it it won't be able to do a discussion scoping property as well such as so you have to be a little careful using them that the state conscience call and all of the parameterization of using this is a world of I want to use I guess the question is and does the parameterization fixtures and that they do not play well with parameterization condone contest certainly and so on tests are explained in case you know it's it's based in all the markers so that you can decorate acids and at that point test of models a parameterized and then given a list of all of its branches and yes that those 2 basically wrote and together but when you do so when when you request things so when you use the decorative parameterized and you have to use requests and request prom again to to get hold of that the value that's been parameterized so so when you when you're requesting the request and which is also which is already can be parameterized and all the parameters that she's just going to get all the combinations again and so yeah this is not always possible for you cooperation on and on on the the words of this already and so the question is but Reitman that pilot tests and cover so use together if you import stuff that's their confessed applied in constant supply followed tends to be strip by converge and someone is not yes and all white or all all all what is on on the 1 hand because what this is that this in 1 of the this is yeah so so an there was also associated with the blood the bloody itself I kind of got can't catch the ball and as as as well as thank for of the the OK so the new did you covers within each of these things all right in but so chooses but and basically means the world Faraday's law here the
Subtraktion
Bit
Gewicht <Mathematik>
Mathematisierung
Klasse <Mathematik>
Hochdruck
Extrempunkt
Service provider
Computeranimation
Übergang
Fluss <Mathematik>
Informationsmodellierung
Ordnungsbegriff
Kontrollstruktur
Funktion <Mathematik>
Basisvektor
Softwaretest
Parametersystem
Lineares Funktional
Befehl <Informatik>
Distributionenraum
Gebäude <Mathematik>
Systemaufruf
Elektronische Publikation
Hochdruck
Quick-Sort
Dienst <Informatik>
Einheit <Mathematik>
Parametersystem
Injektivität
Kantenfärbung
Softwaretest
Prozess <Informatik>
Datenhaltung
Browser
Systemplattform
Menge
Computeranimation
Multi-Tier-Architektur
PROM
Menge
Funktion <Mathematik>
Ruhmasse
Speicherabzug
Ordnung <Mathematik>
Softwaretest
Distributionenraum
Datenhaltung
Graphiktablett
Quick-Sort
Computeranimation
COM
Entscheidungsmodell
Elementare Zahlentheorie
Vorlesung/Konferenz
Innerer Punkt
Tabelle <Informatik>
Normalvektor
Web Site
Abstimmung <Frequenz>
Kartesische Koordinaten
Code
Computeranimation
Internetworking
Multi-Tier-Architektur
Font
Multiplikation
Informationsmodellierung
Softwaretest
RPC
Ordnungsbegriff
Kontrollstruktur
Vorlesung/Konferenz
Datenstruktur
Konfigurationsraum
Regulator <Mathematik>
Normalvektor
Softwaretest
Soundverarbeitung
Nichtlinearer Operator
Lineares Funktional
Sichtenkonzept
Distributionenraum
Datennetz
Einfache Genauigkeit
Ausnahmebehandlung
Elektronische Publikation
Quick-Sort
Konfiguration <Informatik>
Rechenschieber
Maximum-Entropie-Methode
Dienst <Informatik>
Verbandstheorie
Einheit <Mathematik>
COM
Mereologie
Client
Message-Passing
Logik höherer Stufe
Varietät <Mathematik>
Tabelle <Informatik>
Bit
Momentenproblem
Selbstrepräsentation
Mathematische Logik
Computeranimation
Kreisbogen
Knotenmenge
Client
Einheit <Mathematik>
Ordnungsbegriff
Skript <Programm>
Attributierte Grammatik
Einfach zusammenhängender Raum
Softwaretest
Lineares Funktional
Parametersystem
Distributionenraum
Datenhaltung
Hasard <Digitaltechnik>
Systemaufruf
Dateiformat
Elektronische Unterschrift
Quick-Sort
Objekt <Kategorie>
Lemma <Logik>
Einheit <Mathematik>
ATM
Mereologie
Garbentheorie
Information
Subtraktion
Einfügungsdämpfung
Schaltnetz
Computeranimation
Unendlichkeit
Vererbungshierarchie
Ordnungsbegriff
Vorlesung/Konferenz
Bildgebendes Verfahren
Zehn
Attributierte Grammatik
Leistung <Physik>
Softwaretest
Einfach zusammenhängender Raum
Parametersystem
Lineares Funktional
Lipschitz-Bedingung
Befehl <Informatik>
Distributionenraum
Datenhaltung
Gebäude <Mathematik>
Mathematisierung
Mailing-Liste
Quick-Sort
Einheit <Mathematik>
Wort <Informatik>
Zeichenkette
Randverteilung
Resultante
Telekommunikation
Punkt
Versionsverwaltung
Content <Internet>
Kartesische Koordinaten
Information
Lie-Gruppe
Computeranimation
Eins
Netzwerktopologie
Entscheidungsmodell
Ordnungsbegriff
Softwareentwickler
Analysis
Softwaretest
Videospiel
Parametersystem
Lineares Funktional
Distributionenraum
Sichtenkonzept
Namensraum
Konfigurationsraum
Paarvergleich
Farbverwaltungssystem
Mailing-Liste
Strömungsrichtung
Quellcode
Physikalisches System
Elektronische Publikation
Quick-Sort
Objekt <Kategorie>
Menge
Parametersystem
Mereologie
Projektive Ebene
Verzeichnisdienst
Orakel <Informatik>
Server
Abstimmung <Frequenz>
Konfiguration <Informatik>
Selbstrepräsentation
Versionsverwaltung
Computeranimation
Softwaretest
Bereichsschätzung
Syntaktische Analyse
Primzahlzwillinge
Skript <Programm>
Softwareentwickler
Konfigurationsraum
Zehn
Gerade
Softwaretest
Lineares Funktional
Distributionenraum
Vervollständigung <Mathematik>
Kontextbezogenes System
Quick-Sort
Office-Paket
Konfiguration <Informatik>
Objekt <Kategorie>
Dienst <Informatik>
Mereologie
Instantiierung
Standardabweichung
PROM
Softwaretest
Parametersystem
Distributionenraum
Punkt
Kategorie <Mathematik>
Schaltnetz
Verzweigendes Programm
Systemaufruf
Mailing-Liste
Gesetz <Physik>
Quick-Sort
Computeranimation
Internetworking
Bildschirmmaske
Informationsmodellierung
Maskierung <Informatik>
Vorlesung/Konferenz
Wort <Informatik>
Aggregatzustand

Metadaten

Formale Metadaten

Titel Advanced Uses of py.test Fixtures
Serientitel EuroPython 2014
Teil 14
Anzahl der Teile 120
Autor Bruynooghe, Floris
Lizenz CC-Namensnennung 3.0 Unported:
Sie dürfen das Werk bzw. den Inhalt zu jedem legalen Zweck nutzen, verändern und in unveränderter oder veränderter Form vervielfältigen, verbreiten und öffentlich zugänglich machen, sofern Sie den Namen des Autors/Rechteinhabers in der von ihm festgelegten Weise nennen.
DOI 10.5446/19973
Herausgeber EuroPython
Erscheinungsjahr 2014
Sprache Englisch
Produktionsort Berlin

Inhaltliche Metadaten

Fachgebiet Informatik
Abstract Floris Bruynooghe - Advanced Uses of py.test Fixtures One unique and powerful feature of py.test is the dependency injection of test fixtures using function arguments. This talk aims to walk through py.test's fixture mechanism gradually introducing more complex uses and features. This should lead to an understanding of the power of the fixture system and how to build complex but easily-managed test suites using them. ----- This talks will assume some basic familiarity with the py.test testing framework and explore only the fixture mechanism. It will build up more complex examples which will lead up to touching on other plugin features of py.test. It is expected people will be familiar with python features like functions as first-class objects, closures etc.
Schlagwörter EuroPython Conference
EP 2014
EuroPython 2014

Ähnliche Filme

Loading...