« first day (4952 days earlier)   

12:29 AM
@inspectorG4dget ...goes well with bacon
 
 
1 hour later…
1:31 AM
I have yet another dumb question- pytest is recognising my imported functions- but doesn't recognise any of the variables in those functions- what am I doing wrong? (aside from being smoothbrain)
 
 
1 hour later…
2:48 AM
Question: DId the class datetime become immutable between Python 3.6.9 and 3.12.3 ?
(I know that in python 2, it was mutable)
 
3:07 AM
(or maybe not)
 
 
1 hour later…
4:12 AM
@ABcDexter They should be immutable objects
 
 
1 hour later…
5:21 AM
@user24556897 What's the error message?
 
@Aran-Fey It just doesn't recognise any variables from the function? NameError: name 'csv' is not defined
I hate pytest with a passion and cannot get it to work
 
What's the code?
 
def test_data_import():
> assert csv.endswith(".csv") == True
I am not really getting anywhere as it isn't recognising any variables from my function
 
And where did you define the csv variable?
 
It is in the function I am importing into the test.py file
 
5:28 AM
Since when does python let you access variables that are defined inside of another function?
You didn't even call the function
 
@Aran-Fey I tried calling the function first but it still doesn't recognise the variable
 
Yeah, because that's how functions work
If you want to get data from a function, the function has to return it and you have to call the function
 
@Aran-Fey specifically for pytest though- how can I test anything without variables?
 
I really don't know what that means. Pytest isn't some fantasy land where python works completely different than usual. You can use variables in pytest just like you can use them everywhere else. You just have to understand what you're doing and write code that actually works
 
@Aran-Fey Extremely insightful, thankyou
 
5:51 AM
I find decorators confusing in places but to describe them as "being cute" with code. Someone is wrong on the internet
 
I don't really know how LinkedIn works, but it's for people who want to find a job, right? So, uh, that seems like an unwise thing to post there O.o
 
10% trying to get a job, 90% boasting about how smart and virtuous you are for likes
 
6:10 AM
@user24556897 mostly the only magic with pytest is fixtures defined in a conftest.py. Otherwise you have to import modules like you'd always do, and call functions and methods with inputs. Pytest is great and convenient so the issue is on your end.
@Aran-Fey it's work facebook
 
I don't really know how facebook works either ¯\_(ツ)_/¯
 
@AndrasDeak--СлаваУкраїні Thanks :) I am going to have to run through some fixtures tutorials so I understand it properly!
 
@user24556897 no, start with basic tests first
Until you can get csv to work don't look at more magical things
 
@AndrasDeak--СлаваУкраїні but... I want to see magical things...
 
It's not necessarily helped by the fact that csv is also the name of a built-in module
 
6:18 AM
I figured that's what they need
Right, it's a string
 
Yeah, there is no endswith() method on the module
 
so am I right in saying- I can't access the variables of my main file... so I can essentially create mock data using fixtures instead to test with?
 
File or function?
@user24556897 Again, with zero code nobody can help you
If all your work is hidden in a main() then yes, you don't test main(), you use smaller helper functions inside and test those with test data.
And you don't need fixtures, but they are often convenient and useful, especially if you need some cleanup.
 
@AndrasDeak--СлаваУкраїні What my original confusion was with, starting a test_project.py file but being able to access the variables in the main file? but I just have to set the variables in my test_project.py file-?
 
6:29 AM
You can access variables from other files by importing the files
That said, I'm not so sure if that makes sense to do in unit tests. Do you really need variables from another file for your tests?
 
@user24556897 you can access the exact same things as you could in non-pytest modules. That's all I can say and we've said it multiple times already. Go and incorporate this knowledge.
 

« first day (4952 days earlier)