What is this code?

Hi folks! i was reviewing files section and i came across this code that i didn’t realize before, it’s in

Python: Files | Codecademy

and this is the code, it’s in _test file if you want to check for yourself

from os.path import isfile
if not isfile('cool_dogs.txt'):
  fail_tests("Did you create a file called `cool_dogs.txt`?")
with open('cool_dogs.txt') as cd:
  cd_text = cd.read()
  if 'Air Buddy' not in cd_text:
    fail_tests("Did you add `\"Air Buddy\"` to `cool_dogs.txt`?")
  if 'Laika' not in cd_text:
    fail_tests("Did you overwrite `cool_dogs.txt` with a new file? Remember to open in append-mode `\"a\"`.")

Do you have a specific question about it?

Just generally, it’s the internal unit tests that handle the validation for a task, i.e whether you’ve achieved what it’s asking and should get it ticked off - but I’m not sure if you’re after anything more particular?

1 Like

i don’t think so. there are many files that needs validation to check the boxes, almost all lessons. but i didn’t find this test file anywhere else. is it like a toolkit left outside or sth?

Sometimes within lessons you can view the test files. I’ve noticed them in random places on the DS path.

1 Like

so they randomly left code that checks if you did the lesson right out visible?

Generally they’re hidden, not implausible that one slipped though by accident though - I’ve also seen it a few times :slightly_smiling_face:


so they left it on purpose for people to check out?
hmm, maybe they slipped few times? idk, that’s unlikely…right?

I’m sorry, but I don’t see the issue here. (Personally, I think it’s kind of neat to see the code).
I also don’t know what’s in the minds of the devs who wrote the lessons, and I can’t speak for them. Perhaps you can contact customer support & inquire there (?)

nothing is wrong with it(i think…) just was curious for the reason