« first day (4114 days earlier)      last day (817 days later) » 

12:03 AM
(path + '/' + randomFile) was the root of my problem. I will definitely switch to pathlib when I find time to study it. Thank you again for your help.
 
12:14 AM
No problem. Sorry for the rant, I've been in a "everywhere I look I see terrible software" kind of mood lately. I might need to take a break from computers for a decade or two.
 
12:32 AM
I miss my first job as a paper distributor for Metro. I loved the working hours (even had a proper sleep schedule back then) and the lack of any responsibility
Worst thing I could do was give two papers to one person, which was prohibited (but no one cared)
Which is to say that leaving the software industry is tempting
 
And I haven't even entered the industry yet! :D
 
 
6 hours later…
6:47 AM
cabbage
@Hakaishin good
 
 
1 hour later…
8:16 AM
@vaultah room for corruption!
 
8:41 AM
./gasp
 
morning cbg
 
@vaultah lol
 
cbg cbg!
 
8:59 AM
Cbg!
I use .env file to configure a few variables in application.
I would like to be able to test multiple such configurations (and lack of) via pytest.
(Application may crash with one config but not the other)

It seems like no other person tried to achieve something like this, or at least I can't find it.

I think I need to use parametrize and also mock code which loads .env.

I want to ask about your opinion if you think I am going in good direction?
My pytest experience is quite low.
 
https://www.npmjs.com/package/serverless-dotenv-plugin
Read through this topic - Automatic ENV File Resolution
 
And thanks @Aran-Fey for last time answering my question :)
 
Hey. Do you guys know if there's a way to activate/install a way to use regions in VS Code? Regions do not seem to work out of the box for the python language.
 
Might give you an idea of how these people are handling it
@akinuri what region?
 
#region Something like this
Regions allows one to mark lines of codes so they can be collapsed. This helps in organizing code.
 
9:07 AM
@Aqua4 I already use python-dotenv to load .env file. I just wonder how to use multiple such .env files in pytest.
 
I understand wanting to test multiple configurations, but do those configurations really have to be saved in an .env file? Is an .env file the only way to configure your program? There must be a piece of code somewhere that turns the .env file into python variables, right? So can't you just set those variables directly?
 
@KarolZlot If you want to test in different environments, that sounds more like a job for tox than pytest.
 
.env is easier since you can keep seperate files
 
Though a simple pytest approach would probably be to create/place the different .env in a fixture.
 
yea
 
9:13 AM
@Aqua4 that isnt the issue. Aran is saying, you could hijack the mechanism that actually reads the env files during testing. you still get to keep your env files, but the code for testing loads the file/variables that you need
ie, there's a step where things go from env to python variables. have the testing just feed that part of logic. you keep your env files as is.
 
@ParitoshSingh yes if you look at the link i provided those are doing somethinng similar
initially i create env files for different stages, .env.test, .env.dev etc.
then i pass an argument --env=test so my program will autoload from that env file
 
Basically, there are 3 ways to write the code:
1. Make 2 different ways of configuring the app, either through an .env file or by setting the relevant variables
2. Make it possible to customize which .env file the app loads
3. Do neither. This seems to be the current situation, and it's a problem.
 
Ok. Thank you all for pointing direction, it is now more clear for me what approaches to try!
@MisterMiyagi I need to be able to specify per test which sets of environmental variables will be used, sometimes valid, other times invalid. It seems tox doesn't allow to do it as it works on higher level.
I will try other approaches with fixtures etc.
 
Remembering that I've used regions before, it was weird that it didn't work anymore. It seems the issue is related to the python extension. Turning it off helped. Opened an issue in the repo.
 
9:40 AM
@Aran-Fey "So can't you just set those variables directly?"

The problem is that setting os.environ['abc']='123' in any test in pytest doesn't have any effect because those environmental variables were already read earlier with `load_dotenv()`. I will try to use mocking, I see no other solution.
 
Andras bro If your question is eligible for a bounty (>= 48 hours old) and hasn't received a useful response, then you may link to it. is this the rule then I guess I didn't break it because my question is more than 48 hours old
 
But isn't that exactly what load_dotenv does? It reads the values from the .env file and assigns them to os.environ. Right? I don't see why manually updating os.environ wouldn't work
 
@DevilIshere Bro, it was less than 19 hours old when you posted it here
@DevilIshere bro it's still not 48 hours old, bro
 
@KarolZlot what about just having load_dotenv take a param, and during testing you pass it a diff value, or something like that? (just completely guessing here, never used load_dotenv)
or if not, essentially some time spent reworking the code itself so that there's a clear interface for reading the env could make your life easier, essentially removing the need to mock.
 
@Aran-Fey Because I use those environmental to create some objects (as initialization step) so if later environmental variables are changed it doesn't have any effect. I think I didn't design it well and now it backfires.
 
9:50 AM
Looks like now is the perfect opportunity to refactor the code. ;)
 
@MisterMiyagi Yes I'm considering it :)
 
@DevilIshere OK, I came back to my laptop just for you. You asked your question on January 18, 15:29 UTC. You linked it here on January 19, 7:29 UTC, i.e. 16 hours (also one calendar day) later. Now it's January 20, 9:53 UTC. Your question won't be 48 hours old for another 5 and a half hours. If you want to get away with lies I suggest trying your hand at something that doesn't involve unicode timestamps.
 
10:47 AM
Step 1: Come up with a punny package name
Step 2: ???
Step 3: Profit
works every time
 
2. Squat the package name and wait for a buyer
 
this_is_fine.jpg
 
11:12 AM
@NothingnessIsavirtue I already explained once in very clear terms. You're welcome to chat here about other things, but we're done discussing this.
 
 
1 hour later…
12:46 PM
@Aran-Fey Oh I see, nice
 
 
1 hour later…
2:06 PM
@ParitoshSingh Thanks also for your suggestions, I plan to rework my code so mock isn't needed :)
 
 
1 hour later…
3:18 PM
Something tells me, that here accessing globals() and modifying it like this isnt the best method since we can just store it into a list.
 
Yep
 
I have left a comment, but IDT the OP would mind, given that they already received an answer and the code works fine now
Dec 30 '21 at 19:24, by Kevin
"If it's dumb and it works, it's not dumb" -- ancient wisdom
 
Nah, using globals() instead of a dedicated dict is dumb.
 
Maybe they don't know that yet, a comment with a link or explanation could be the best efforts from a stranger here
 
I'm sure we have a dupe target for "How do I create and access a dynamic number of variables, whose names are all the same except for a digit?" lying around somewhere
It's basically the most common design antipattern
 
3:32 PM
 
How do these people figure out how to dynamically create globals before they learn to use a dict?
Actually it's even worse because the globals are a dict. So they do know how to use a dict, they just don't know that they know
 
@Aran-Fey youtube videos and crap SO questions, same vibes as "eval, so cool, wow"
 
Can we find and burninate those SO questions?
 
Perhaps there's a small window of opportunity where they know how to assign to a dict, but don't know how to create one
 
No, they want to use variables
If you tell them to use a single container instead you're literally a nazi
 
3:39 PM
All the top results I can find already say "use a dict". I don't know how to google badly enough to find bad results
 
Google knows you want the good stuff
 
you have to wipe your search history
exactly
 
Try searching on geeksforgeeks or something
 
only then can you forge the path of descent to madness for yourself
 
madness is under-rated - I love it! :p
 
3:46 PM
cute puppy madness – Yes! geeksforgeeks madness – No!
 
I bet some youtube video might have said that this was the best method
Or they mustve gone out of luck and searched and found out globals
 
Can we buy youtube and take those videos down?
 
If I cast my mind back, I think I actively wanted variable variables even when I knew about dictionaries
Or whatever the canonical's name is. I understood names, but not the context of dictionaries in my problem. And I don't think I would have appreciated that globals() was a dict
 
They should just turn globals() into a set of contextvars. No one uses those voluntarily.
 
4:01 PM
It's just a means to an end, and if the only end you know of is creating variable names, well there it is
 
I will say, this dynamic variable/globals problem though, has never been a huge hurdle for me. People seem receptive to "dont do that, use a list/dict" for this problem, they just need someone to tell/show them how to do it.
But maybe i've been lucky with that one? not sure.
 
Yeah it's usually not hard to make them use a dict instead, I'm just wondering why we have to do it so often
I understand that it's the "obvious" solution for a beginner, but how do they figure out how to do it when all the google results say "use a dict"?
 
I think it may come from early exposure to exec(), which is often found in these define-a-bunch-of-variables cases.
 
Wait, really? Oof, that's even worse
 
okay, i did an experiment for science. in incognito: i searched "how to make multiple variables in a loop python". that led me to dictionary answers. but i searched "how to make vartiables from string python" and the can of worms was opened. stackoverflow gave a exec result. and what's sad is that some website that gave the dictionary approach for the first result now gave the globals/locals approach instead.
(and yes, i did that search with the typo. for authenticity ofcourse, totally didn't mess it up myself...*cough*)
 
4:15 PM
@Aran-Fey I think you don't appreciate frame challenges when you're very nooby
 
Interesting. All my SO results go to the "how do I do variable variables?" question, but my top result is an excerpt from this, where google literally lists globals, locals and exec as the 3 solutions
 
Everything is hard and confusing and I just want my variable variables
And never forget that all the newbies who find the right approach never ask on SO
 
the trick is in appreciating that "variable variables" itself is not going to be the query beginners search for. it's often more...off the mark. you have to search as if you don't know the answer....or the question.
 
People of any skill level can get bristly if you tell them "the thing you want is silly and you should not want to do it. Here's how to do this other thing, which you should want instead", but neophytes in particular can be hard to convince
 
@AndrasDeak Hmm, you may have a point. I assumed most newbies wouldn't bother scrolling further than the top answer and just copy/paste the code that uses a dict
 
4:20 PM
@Aran-Fey i'll one up you. if, heaven forbid, there's code in the question, most newbies don't scroll to the first answer, and copy the borked code from the question instead.
I admit, that one was a curveball for me. I just had to stare in disbelief for a few seconds.
 
I recall one user that was skeptical of some suggestion I made. Over the course of half an hour I made 4 or so different arguments supporting my view, but he wasn't convinced, possibly because he didn't understand any of them. Finally, as a joke, I tried an argument from authority: "this is the most Pythonic and community-accepted approach". He replied, "Oh! Okay, I'll use it then. Why didn't you say so earlier?"
 
perhaps most is incorrect. but it happened more than 0 times. it shouldn't have happened more than 0 times.
 
I may have actually said in chat "I'll try an argument from authority now"
 
4:35 PM
@ParitoshSingh Haha, I do that sometimes. When I'm working with something unfamiliar that just refuses to make any sense to my poor brain, then any code at all is better than nothing! And sometimes I then forget to apply the fix from the answer(s)...
 
 
2 hours later…
6:59 PM
How to calculate cumulative sum for choosing neighbour(8 or 4 mechanism) node in this below ACO approach?
https://stackoverflow.com/questions/23584460/ant-colony-optimization-movement-of-ants
 
7:20 PM
This is a nifty trick for cookie preferences (for those covered by the GDPR). Invert the slider so that the top setting has the lowest privacy invasion
What a farce :/
Actually, given what I know of SAP, I suppose it's entirely within character to trick a visitor to think they were lowering the cookie invasion by lowering the slider, whilst they're actually opting in to more cookies
 
Has anyone used these pandas tutorials and could recommend one? The quick intro is actually pretty brutal IMO, but not sure what best to direct a colleague to
 
 
2 hours later…
9:57 PM
@roganjosh I really like Wes McKinney's Pandas book. It starts a little slow, but there's a lot of good stuff in there. I just wish there was a newer version available that covers more recent changes to the library, but a lot of what's in there is still applicable.
It seems like a lot of the tutorials on that page are rather dated...
 
10:12 PM
How should I approach setting up integration test for a Django REST API app? i.e. I want to spin up a development server locally and then make some calls against it. Have a test script that in a subprocess spins up a local Django server, wait a bit, and then make calls against it? Any tools I should use to make it less hackish?
 
10:24 PM
@MattDMo Thanks, I'll go with that. I haven't got time to properly review other tutorials and I'm growing increasingly distrustful of things that aren't officially endorsed, so it's a shame they've not brought things up to date
 

« first day (4114 days earlier)      last day (817 days later) »