Are you confused about pytest's fixtures?

Do you struggle to understand them?

#100daysOfCode #pytest #Python

🧵This one is for you👇
1️⃣ pytest's fixtures are functions decorated with "pytest.fixture" decorator

They can return value or produce side effects like creating/removing a database.

They can be located inside conftest.py or inside the test file.
2️⃣ To use the value returned from the fixture function inside a test you need to add a parameter with the same name as the fixture function.
3️⃣ You can run part of the fixture before the test function (before yield) and the part after (after yield).

For example:
* create ES index before test function
* remove ES index after test function
👇
4️⃣ A fixture can accept parameters when using factories

It returns the factory method instead of value.

You can use the factory method inside a test to get a value based on provided parameters

For example, create users with different usernames👇
5️⃣ By default, fixtures run before/after each test - scope='function'.

You can change the scope of the fixture using the *scope* parameter:

* 'module' - before/after all tests in the module
* 'session' - before first and after the last test in the test suite
👇
6️⃣ You can provide multiple different fixtures to the same test by using

* fixture's params argument
* pytest's request

An example 👇
7️⃣ pytest also provides built-in fixtures like:

- tmp_path: pathlib.Path object to a temporary directory unique to each test function
- request: information on the executing test function
- caplog: Control logging and access log entries
- ...

Examples 👇
8️⃣ You can read more in their official docs

docs.pytest.org/en/latest/fixt…

• • •

Missing some Tweet in this thread? You can try to force a refresh
 

Keep Current with Jan Giacomelli

Jan Giacomelli Profile picture

Stay in touch and get notified when new unrolls are available from this author!

Read all threads

This Thread may be Removed Anytime!

PDF

Twitter may remove this content at anytime! Save it as PDF for later use!

Try unrolling a thread yourself!

how to unroll video
  1. Follow @ThreadReaderApp to mention us!

  2. From a Twitter thread mention us with a keyword "unroll"
@threadreaderapp unroll

Practice here first or read more on our help page!

More from @jangiacomelli

1 Dec
Don't know where and how to start with ML?

#100daysOfMLCode #100daysOfCode

🧵This is my journey so far👇
1️⃣ I started with ML during my master's degree.

I decided to try to build a model of my guitar amplifier.

I started with this course:

udemy.com/course/machine…
2️⃣ After I finished it I started playing around with Keras and scikit-learn to build a model of my guitar amplifier.

It took 72 hours of recording, 250+ hours of training, and 6 months of experimenting to conclude - ML algorithms like NN won't produce anything useful.
Read 12 tweets
30 Nov
☁️ AWS is a great choice for a startup

Here are some reasons why

#100daysOfCode #100daysOfMLCode #AWS

🧵👇
1️⃣ Free tier

Most of the services offer free tier for first 12 months since registration.

There are enough free resources per month that you're able to build MVP for almost free.
2️⃣ Designed for scalability

All of their services are designed with scalability in mind.

You can scale your startup business without limits.
Read 8 tweets
29 Nov
Don't know how to land your first tech job?

It's not easy but it's possible

🧵This is how I did it👇

#100daysOfCode #100daysOfMLCode
It was starting my master's at university in electrical engineering.

For some reason, I decided to try to get a job as a software engineer to increase my income.

I knew how to program in Matlab & C. It was enough to pass exams but not enough to build a project from scratch.
I decided to learn the basics of Javascript, PHP, and Laravel.

I built a couple of small and simple projects (e.g. web page for my band with Laravel).

I searched for open positions in my town. I didn't meet more than 25% of the requirements for any of them.
Read 8 tweets
24 Nov
🤷‍♂️You've learned basics of Python and you don't know what to do next?

How to go from "hello world" to real applications?

🧵 This one is for you👇

#100daysOfCode #100DaysOfMLCode #Python
1️⃣ Build expense tracker CLI app.

Each expense should have following attributes:
* title (string)
* amount (float)
* created_at (date)
* tags (list of strings)

Store expenses in TXT file.

Cover: Add expense, list expenses, get expense, edit expense, delete expense
2️⃣ Add database

Instead to storing/reading in/from TXT file start using SQLite.

Write script to copy all of the existing expenses from TXT file to database.

Don't use ORM at this point.
Read 14 tweets
23 Nov
Python is a great choice for the main backend programming language in a startup

Here are some reasons why

#100daysOfCode #100daysOfMLCode #Python #Startup

🧵👇
1️⃣ Easy to write & easy to read

It reads and writes almost like the English language. You need a small amount of code to get a job done. You'll probably rewrite it at least 3 times.
2️⃣ 1st class citizen on cloud platforms

You don't want to deal with physical servers in a startup. You just want to run your app. Python has cloud SDK libraries, it runs on serverless platforms, it's used in ML services, a lot of examples in cloud docs are using Python.
Read 7 tweets

Did Thread Reader help you today?

Support us! We are indie developers!


This site is made by just two indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member ($3/month or $30/year) and get exclusive features!

Become Premium

Too expensive? Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal Become our Patreon

Thank you for your support!

Follow Us on Twitter!