Yes i agree too with @Priyadapanicker
However, You asked if writing code before the test breaks TDD. Technically yes , but it’s fixable.
For example, in your current code, the DirectoryContainsNifRecursively()
method is being tested after it was already implemented.
A TDD move would be:
First, write this failing test:
def test_search_path_contains_nif_files(setup_nifExplorer):
for obj in setup_nifExplorer:
assert obj.DirectoryContainsNifRecursively(obj.SearchPath)
Then, implement the actual DirectoryContainsNifRecursively()
logic just enough to make this test pass.
This workflow ensures that every behaviour is driven by a test and you never write unused or overengineered code. You can even stub the method initially with a return False to see the red → green flow in action.
Hope this helps