Test wont pass on #V74 when running #EL9

I’m stuck on Stage #EL9). When I run the test that works, but then it goes to test #V74 and fails even though I passed it before.

It will say it expects (“”) and says my output is wrong. So I go to my code and change the code to match what it expects and THEN it will tell me it expects the output that it was already outputting. I dont know how to resolve this

Here are my logs:


Logs
[compile] Moved ./.codecrafters/run.sh → ./your_program.sh
[compile] Compilation successful.
Debug = true
[tester::#EL9] Running tests for Stage #EL9 (Redirection - Append stdout)
[tester::#EL9] Running ./your_program.sh
[tester::#EL9] Writing file "/tmp/foo/apple" with content "apple"
[tester::#EL9] Writing file "/tmp/foo/orange" with content "orange"
[tester::#EL9] Writing file "/tmp/foo/pear" with content "pear"
[your-program] $ ls /tmp/foo >> /tmp/bar/foo.md
[your-program] $ cat /tmp/bar/foo.md
[your-program] apple
[your-program] orange
[your-program] pear
[tester::#EL9] ✓ Received redirected file content
[your-program] $ echo 'Hello James' 1>> /tmp/bar/qux.md
[your-program] $ echo 'Hello Emily' 1>> /tmp/bar/qux.md
[your-program] $ cat /tmp/bar/qux.md
[your-program] Hello James
[your-program] Hello Emily
[tester::#EL9] ✓ Received redirected file content
[your-program] $ echo "List of files: " > /tmp/bar/quz.md
[your-program] $ ls /tmp/foo >> /tmp/bar/quz.md
[your-program] $ cat /tmp/bar/quz.md
[your-program] List of files:
[your-program] apple
[your-program] orange
[your-program] pear
[tester::#EL9] ✓ Received redirected file content
[your-program] $ 
[tester::#EL9] Test passed.
[tester::#VZ4] Running tests for Stage #VZ4 (Redirection - Redirect stderr)
[tester::#VZ4] Running ./your_program.sh
[tester::#VZ4] Writing file "/tmp/baz/orange" with content "orange"
[your-program] $ ls nonexistent 2> /tmp/quz/bar.md
[your-program] $ cat /tmp/quz/bar.md
[your-program] ls: nonexistent: No such file or directory
[tester::#VZ4] ✓ Received redirected error message
[your-program] $ echo 'James file cannot be found' 2> /tmp/quz/foo.md
[tester::#VZ4] Expected file content ("") but received "James file cannot be found\n"
[your-program] $ 
[tester::#VZ4] Assertion failed.
[tester::#VZ4] Test failed

And now I will change a line of code and test it again and look what it says now...


[compile] Moved ./.codecrafters/run.sh → ./your_program.sh
[compile] Compilation successful.
Debug = true
[tester::#EL9] Running tests for Stage #EL9 (Redirection - Append stdout)
[tester::#EL9] Running ./your_program.sh
[tester::#EL9] Writing file "/tmp/quz/banana" with content "banana"
[tester::#EL9] Writing file "/tmp/quz/mango" with content "mango"
[tester::#EL9] Writing file "/tmp/quz/pineapple" with content "pineapple"
[your-program] $ ls /tmp/quz >> /tmp/baz/bar.md
[your-program] $ cat /tmp/baz/bar.md
[your-program] banana
[your-program] mango
[your-program] pineapple
[tester::#EL9] ✓ Received redirected file content
[your-program] $ echo 'Hello Maria' 1>> /tmp/baz/baz.md
[your-program] $ echo 'Hello David' 1>> /tmp/baz/baz.md
[your-program] $ cat /tmp/baz/baz.md
[your-program] Hello Maria
[your-program] Hello David
[tester::#EL9] ✓ Received redirected file content
[your-program] $ echo "List of files: " > /tmp/baz/foo.md
[your-program] $ ls /tmp/quz >> /tmp/baz/foo.md
[your-program] $ cat /tmp/baz/foo.md
[your-program] List of files:
[your-program] banana
[your-program] mango
[your-program] pineapple
[tester::#EL9] ✓ Received redirected file content
[your-program] $ 
[tester::#EL9] Test passed.
[tester::#VZ4] Running tests for Stage #VZ4 (Redirection - Redirect stderr)
[tester::#VZ4] Running ./your_program.sh
[tester::#VZ4] Writing file "/tmp/quz/strawberry" with content "strawberry"
[your-program] $ ls nonexistent 2> /tmp/foo/baz.md
[your-program] $ cat /tmp/foo/baz.md
[your-program] ls: nonexistent: No such file or directory
[tester::#VZ4] ✓ Received redirected error message
[your-program] $ echo 'Emily file cannot be found' 2> /tmp/foo/qux.md
[your-program] $ 
[tester::#VZ4] Output does not match expected value.
[tester::#VZ4] Expected: "Emily file cannot be found"
[tester::#VZ4] Received: "$ "
[tester::#VZ4] Assertion failed.
[tester::#VZ4] Test failed

And here’s a snippet of my code:

  # Handle output and error redirection
            if stdout_file:
                ensure_directory_exists(stdout_file)
                with open(stdout_file, stdout_mode) as f:
                    f.write(" ".join(parts[1:]) + "\n")
            elif stderr_file:
                ensure_directory_exists(stderr_file)
                with open(stderr_file, stderr_mode) as f:
                    f.write(" ".join(parts[1:]) + "\n")

this is the code that got me the first error, then, just to test it to match the ("") it was expecting for troubleshooting, I changed the last line of code to just say 
f.write("") and thats what got me the other error saying it was looking for what I initially had in the first place. Its like its going in circles and Im not sure where the issue is

Hi @EricBrown56, could you upload your code to GitHub and share the link? It will be much easier to debug if I can run it directly.

I think the issue lies in line 68. Anytime I change it, it expects (“”) and I have no idea how to fix it at this point. It worked just fine previously otherwise I would not have made it to the next test

Ok it works now. I had to change the line on line 68 to say sys.stderr.write instead of f.write

1 Like

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.