with django projects, you often have a lot of declarative code, and thus you can very very easily reach 100% branch coverage without actually testing very much
i am totally guilty of this :p
keltvek has quit
Koterpillar
that's not a bad thing
less code = less places to go wrong
moldy
the bad thing here is the false sense of security
Koterpillar
of course, it doesn't test that it does what you _want_
Hairy has quit
Cavedude has quit
jwarren_ joined the channel
coverage of X% only tells you, "we have no idea what (100-X)% of our code is doing"
moldy
i should listen to my inner jessamynsmith more often ;)
nedbat
Koterpillar: that is pithy
morenoh149
is there a pip command which will install a dep and record it in requirements.txt?
nedbat
Koterpillar: you should tweet it (or I will!)
jessamynsmith
yes, I do not like false sense of security
Koterpillar: :)
Koterpillar
morenoh149: pip install <stuff> && pip freeze
nedbat
morenoh149: you should update requirements.txt by hand, it isn't hard.
morenoh149
I'm just used to --save-dev in npm
Cavedude joined the channel
Koterpillar
morenoh149: consider pip-tools
morenoh149
and --save
nedbat
morenoh149: pip freeze has good and bad points
moldy
since a few months, my projects enforce 100% branch coverage in the build. it is a little shocking to realize how easy you can get 100% branch coverage with really crappy tests ;)
jessamynsmith
morenoh149: it is nice, and would be nice if pip did similarl
oh!
moldy: I don't enforce 100% for that very reason
morenoh149
I feel like such a noob rn
nedbat
moldy: jessamynsmith's point is the key: running the code is useless without good verification of the results.
jwarren_
Ladies and gents, I'm running into a weird issue I'm not sure how to solve. I have a model, like User, that has a 1-1 relationship with a Profile. On my URL routes, I want to be able to do something like /user/1/profile, but when I plug that into my routes it breaks saying that /user/{pk}/profile{pk} is an invalid redefinition of PK. Ideas?
mastokley joined the channel
moldy
jessamynsmith: my reasoning is that 100% crappy coverage is still better than 99% crappy coverage ;)
linx joined the channel
Koterpillar
nedbat: why the second {pk}?
jessamynsmith
I like honest coverage, whatever the percent
moldy
but my actual reason is that it just forces us to write at least some tests :p
jessamynsmith
heh
linx has quit
moldy
it's a lame way of disciplining myself, but it works
nedbat
Koterpillar: mis-nick?
Koterpillar
what?
jwarren_
Koterpillar: There is no second PK. It's like Django is expecting that there would be a second PK, as a detail or something. It's not in the URL conf path regex at all.
moldy
relaxing the 100% coverage requirement feels like defeat, so i rather write that test :p
moldy: the downside of 100% coverage is, your code ends up littered by #pragma statements
jwarren_: I bet ProfileViewSet adds a {pk} to the end of whatever you give it
jwarren_
(I'm using Django Rest Framework if that makes any diff)
Koterpillar
jwarren_: it totally does
jwarren_: not familiar with DRF but maybe there's a way to configure how ViewSets insert the /{pk} bit
CtrlC joined the channel
moldy: I require pylint 10, for example, and sometimes that means a lot of pragmas
jwarren_
Got it, thanks Koterpillar
roflmyeggo joined the channel
moldy
Koterpillar: i don't know pylint 10, but yeah, i enforce flake8 and even isort on my build :p
Koterpillar
FYI pylint can be configured to act like isort
aron_kexp has quit
FunkyBob
nedbat: awake? am getting odd results with coverage, showing my template tags are never run
nedbat
FunkyBob: let's look at it!
Lobstaman3 has quit
FunkyBob
on github... django sniplates...
pilne
TDD is such a heavy influence on so many tutorials and coding in general it seems, yet i'm having a hard time adapting my thinking to it >.<
nedbat
FunkyBob: if you have a link to the repo and the coverage results, that will help
b0nn joined the channel
cnk
pilne: any partiuclar aspect?
Koterpillar
pilne: hugely rewarding
moldy
nedbat: i agree that verification should be done, but to my defense: even just running the code is still better than not running it at all ;) you get the implicit verification that it doesn't throw an exception
Koterpillar
pilne: so is quickcheck
cnk
if it is just 'testing is hard', it just is
nedbat
moldy: sure, but there's nothing left to tell you where to add better tests.
FunkyBob
just updated coverage, but your django templates coverage plugin won't install : http://dpaste.com/29ZC8NH
cnk
and esp when you dn't have a clear idea of where you are going
asheinfeld joined the channel
pilne
no, it isn't testing is hard... but.. years ago when i first learned to code, you wrote the tests after a function, and i'm still more in that mindset
i had a long hiatus... last time i coded (before picking it up again recently) was when java 1.2 was the new hotness
Koterpillar
pilne: yeah, get out of it - you'll be tempted to write tests that succeed
you should write tests that fail
kingarmadillo has quit
nedbat
FunkyBob: that's not mine. You want django_coverage_plugin
FunkyBob
oh, ok
moldy
nedbat: true. but then again, with frameworks like django, it is sometimes rather unclear where to draw the line.
nedbat
FunkyBob: (I had to look up the name again!)
FunkyBob
yep, that went in fine
nedbat: yeah, I was guessing too :)
pilne
i understand that Koterpillar, i truly do, i just can't seem to figure out how to get into that mindset
FunkyBob
nedbat: so, all tests run, and pass... but...
moldy
nedbat: you can test many CBVs by just importing the module. otoh, if you functional-test them, you test mostly framework code, not your own.
Koterpillar
pretend that your function is already written, but by me, and I'm evil
beardedeagle joined the channel
moldy: you test framework code + your _configuration_
FunkyBob
Koterpillar: or incompetent :)
pilne
so, figure out what i want the function to do, everything it shouldn't do, write tests to verify these things, then create the function?
b0nn has quit
cnk
that's the theory
FunkyBob
we explaining TDD to pilne ?
Koterpillar
yes?
nedbat
FunkyBob: how can i see the results?
cnk
One school of thought is the point of TDD isn't testing, it's design
Koterpillar
okay, four levels: things it should normally do, things it must not do (hard cases?), incompetent mistakes, evil behavior
cnk
if something is easy to test, it is usually pretty decoupled
Koterpillar
^
moldy
Koterpillar: yes, but you have to draw the line somewhere, and it's not always entirely obvious where to draw it
audio joined the channel
xall joined the channel
Koterpillar
moldy: you usually have external requirements
moldy: if your requirement is "build some views that don't crash", fine
pilne
Koterpillar: i can get the first two in my head easily, but the last two... especially the last one, i'm not confident in my ability to "think of" before it bites me in the ass
Koterpillar
pilne: that'll do. You can iterate on this: make tests, write the code to pass them - but be lazy here :)
e.g. if your test of (+) is 2+2 = 4, write it as "return 4"
moldy
Koterpillar: i am more thinking about things like authentication / permissions, that can be quite easy to break with declarative code without either your tests noticing or coverage going down
Hairy joined the channel
Koterpillar
moldy: I will generally point at quickcheck but I'm not sure it will be suitable to testing something this large
Hairy has quit
beardedeagle has quit
moldy
for me, a big part of testing is not "do i meet the requirements", but rather "did this change break anything that i did not expect it to break" :=
i never have requirements that can be turned into tests anyway :p
Koterpillar
hmm, never? example?
Hairy joined the channel
moldy
Koterpillar: i basically never have written requirements, and if i have them, they are all lies
kripx has quit
and they change every time i ask for clarification
Koterpillar
how do you convince people that you've fulfilled them then?
schinckel
willpower
WeiJunLi_ is now known as WeiJunLi
Koterpillar
how do you convince _yourself_ that you've fulfilled them then?
Hairy has quit
moldy
Koterpillar: i usually don't
schinckel
never underestimate the power of self-delusion
Koterpillar
heh
moldy
i just let stuff run and wait for complaints
requirements are a big myth :p
domino14_ has quit
krwl_ has quit
asheinfeld has quit
kriwil joined the channel
it's a silly phantasy. as if the customer wrote the test cases, and if you pass them, you did your job. maybe some people work like that, but i dare to say 99% of us don't :p
Koterpillar
somewhere between that and "reproduce a week of incoming TCP packets with identical results" the truth lies