Getting started with pytest Transcripts
Chapter: Test Functions
Lecture: A dataclass called Card
Login or
purchase this course
to watch this video and the rest of the course contents.
0:00
So you want to start taking a look at writing a test for the cards. Project. The cards, project source code is in the directory,
0:10
in the pytest course directory, there is a cards project directory within the editor we can see it as well.
0:17
And inside there there's a source directory and there's some a test directory and license make file and stuff, within the source directory,
0:28
there's a source cards and the CLI is the command line interface. So that's if we type cards, we get the the interface and or you know,
0:41
help or whatever there is. That's the command line interface, the API Is below that. It's a three layer structure and so all the CLI will talk
0:53
to the API. So hopefully in the CLI we've got an import of the API. Somewhere import cards. It's just importing the cards directly.
1:01
That's because we have init here that allows that to happen within the init it imports everything from the API
1:07
So the CLI imports cards which indirectly imports the API. The API will import the database.
1:19
And so we've got the cli on the top calling the Api which calls the database we're going to take a look at a data class within the
1:30
API. This class this is called the state of structures called card and it holds a summary and an owner and a state and an ID.
1:39
And that represents each individual item. So the ID. State owner and summary.
1:46
The there's some fancyness going on here if you're not familiar with data classes, that's kind of what we're doing right now is testing this.
1:53
Um and we're gonna write some knowledge building tests around making sure we understand how this
2:00
data structure works. And the data structure is used to pass information between the cli and the API.
2:06
And back. And so it's kind of an important data structure within our application The defaults are set on the right so these are string string,
2:16
string and int and the defaults are none none to do. And this is the field is a part of the data classes interface that
2:26
is setting the default to none for an int for the ID. And setting compared to false.
2:33
And that is so that when we compare two cards that have equal state owner in summary they will show up as equal even if they have a different ID.
2:43
And then I added a couple of helper methods. This is used within the source code to pass to switch between dictionaries and
2:52
card the card class card objects. And these are not necessary. You can use the as dict or the star star
2:59
but I for me I think from dict and to dict are a little more clear so I've added those so I'm gonna write a couple of tests to sort
3:10
of make sure that I understand how this data class works.