Help with a simple test

Hi! I am trying to set up some simple coding assignments for students and I’m trying to use the Input/Output testing but must be doing something wrong as it seems to disregard the printed output from the program and treats the user input as the output. The program takes a given integer and prints Even or Odd depending on the number, works as expected when run but tests fail.

test result

It seems so simple to set up but I must be going wrong somewhere?

3 Likes

Can you possibly give us the code?

1 Like

Hey @byranth welcome to the forums!

The I/O test is looking for the output that says Even and not an even number. A unit test that checks if its even or not would be better for this.

4 Likes

Well the code seems to print the number instead of printing Even or Odd. Like @Sky said, please give us the code.

2 Likes

A workaround from a recent related topic:
https://ask.replit.com/t/tests-do-not-work/61097/3

which came from a bug report topic:
https://ask.replit.com/t/tests-not-working/60902

which was split, creating another topic:

Thanks for the responses, here is the code: https://replit.com/@code-recap/Odd-or-Even#main.py

I am experiencing the same thing as described in past threads linked by @NuclearPasta0. As these users described, the option for Unit Tests is also greyed out for me with the message that it is not supported for this language. The workaround seems to be to copy and old functioning repl and reuse it but this is my first repl in Replit classrooms.

1 Like

I have a repl that should work for this. According to 14-15th posts in the second topic, the fix still leaves a remaining issue. Consult the second topic for more details.


However, I have a theory as to an easier solution that may work. Can you test this first to see if it works?
Show hidden files (in three dots menu) and open the .replit file.
Insert the following code anywhere in the file, do not delete or replace anything:

# Enable unit tests. This is only supported for a few languages.
[unitTest]
language = "python3"

If that doesn’t work, you can use the original solution:
First, show hidden files, then you can replace all of the contents of each file:
In .replit file:

# The command that runs the program. If the interpreter field is set, it will have priority and this run command will do nothing
run = "python3 main.py"

# The primary language of the repl. There can be others, though!
language = "python3"
entrypoint = "main.py"
# A list of globs that specify which files and directories should
# be hidden in the workspace.
hidden = ["venv", ".config", "**/__pycache__", "**/.mypy_cache", "**/*.pyc"]

# Specifies which nix channel to use when building the environment.
[nix]
channel = "stable-22_11"

# The command to start the interpreter.
[interpreter]
  [interpreter.command]
  args = [
    "stderred",
    "--",
    "prybar-python310",
    "-q",
    "--ps1",
    "\u0001\u001b[33m\u0002\u0001\u001b[00m\u0002 ",
    "-i",
  ]
  env = { LD_LIBRARY_PATH = "$PYTHON_LD_LIBRARY_PATH" }

[env]
VIRTUAL_ENV = "${REPL_HOME}/venv"
PATH = "${VIRTUAL_ENV}/bin"
PYTHONPATH = "$PYTHONHOME/lib/python3.10:${VIRTUAL_ENV}/lib/python3.10/site-packages"
REPLIT_POETRY_PYPI_REPOSITORY = "https://package-proxy.replit.com/pypi/"
MPLBACKEND = "TkAgg"
POETRY_CACHE_DIR = "${REPL_HOME}/.cache/pypoetry"
POETRY_INSTALLER_MODERN_INSTALLATION = "0"

# Enable unit tests. This is only supported for a few languages.
[unitTest]
language = "python3"

# Add a debugger!
[debugger]
support = true

  # How to start the debugger.
  [debugger.interactive]
  transport = "localhost:0"
  startCommand = ["dap-python", "main.py"]

    # How to communicate with the debugger.
    [debugger.interactive.integratedAdapter]
    dapTcpAddress = "localhost:0"

    # How to tell the debugger to start a debugging session.
    [debugger.interactive.initializeMessage]
    command = "initialize"
    type = "request"

      [debugger.interactive.initializeMessage.arguments]
      adapterID = "debugpy"
      clientID = "replit"
      clientName = "replit.com"
      columnsStartAt1 = true
      linesStartAt1 = true
      locale = "en-us"
      pathFormat = "path"
      supportsInvalidatedEvent = true
      supportsProgressReporting = true
      supportsRunInTerminalRequest = true
      supportsVariablePaging = true
      supportsVariableType = true

    # How to tell the debugger to start the debuggee application.
    [debugger.interactive.launchMessage]
    command = "attach"
    type = "request"

      [debugger.interactive.launchMessage.arguments]
      logging = {}

# Configures the packager.
[packager]
language = "python3"
ignoredPackages = ["unit_tests"]

  [packager.features]
  enabledForHosting = false
  # Enable searching packages from the sidebar.
  packageSearch = true
  # Enable guessing what packages are needed from the code.
  guessImports = false

# These are the files that need to be preserved when this 
# language template is used as the base language template
# for Python repos imported from GitHub
[gitHubImport]
requiredFiles = [".replit", "replit.nix", ".config", "venv"]

[languages]

[languages.python3]
pattern = "**/*.py"

[languages.python3.languageServer]
start = "pylsp"

[deployment]
run = ["sh", "-c", "python3 main.py"]

In replit.nix file:

{ pkgs }: {
  deps = [
    pkgs.python310Full
    pkgs.replitPackages.prybar-python310
    pkgs.replitPackages.stderred
  ];
  env = {
    PYTHON_LD_LIBRARY_PATH = pkgs.lib.makeLibraryPath [
      # Needed for pandas / numpy
      pkgs.stdenv.cc.cc.lib
      pkgs.zlib
      # Needed for pygame
      pkgs.glib
      # Needed for matplotlib
      pkgs.xorg.libX11
    ];
    PYTHONHOME = "${pkgs.python310Full}";
    PYTHONBIN = "${pkgs.python310Full}/bin/python3.10";
    LANG = "en_US.UTF-8";
    STDERREDBIN = "${pkgs.replitPackages.stderred}/bin/stderred";
    PRYBAR_PYTHON_BIN = "${pkgs.replitPackages.prybar-python310}/bin/prybar-python310";
  };
}
1 Like

Hey all!

I am sorry that you are having issues with testing. I was able to reproduce the issue with I/O tests and have flagged this to the team.

So I can gather more context, your issues are only with I/O tests and not unit tests, correct?

My unit tests are not working anymore. I have a simple input/output test but any time I use text, the results are not working correctly and it does not seem to be outputting any data

I have even simplified the tests to make sure I am not doing anything wrong. This one should pass the test if the output is “words should appear”
It still fails the test. Any ideas?

Also experiencing this same issue. I/O tests for new replit python projects are no longer working. My print statements no longer appear in the output. I can’t even get a “Hello World” program and test to run presently.

2 Likes

Brief followup from another thread:
I was able to figure out a workaround. The .replit and replit.nix files for new Python repls in teams seem to be almost entirely blank! After copying the contents from an older, known-working Python project in repl teams, I was able to get the unit tests in my project to work. Try this and see if it works for you. Hopefully they fix this issue as soon as possible.

2 Likes

I’m so happy to have stumbled on this. I have been banging my head for the last 48 hours trying to figure out what I was doing wrong. Hopefully this is fixed SOON.

2 Likes

first step is to take it out of light mode. that should solve alot of your problems.

1 Like

Same here! Was prepping an assignment for kids and spent a couple hours trouble shooting. Mayday, replit, mayday!

1 Like

I’m getting a similar issue. Input/output tests failing for correctly executing code. In my version of this bug, the “Actual Output” is not blank, it’s just incorrectly showing the what was input, not what was output.

I am experiencing the exact problem that ChrisBomba is experiencing. No matter what the actual output is, what’s in the input field is captured as an output.

I’m new to Replit and I don’t have any old code, so not sure how to use this workaround. Also, how do I view the .replit and replit.nix files to check?

1 Like

In the “Files” pane, click on the three dots and select “Show hidden files”. That should show you the .replit and replit.nix config files. Below is a copy of my config files should you not have any in a known working state. Granted these files are a little bit older, but should work.

replit.nix

{ pkgs }: {
  deps = [
    pkgs.python310Full
    pkgs.replitPackages.prybar-python310
    pkgs.replitPackages.stderred
  ];
  env = {
    PYTHON_LD_LIBRARY_PATH = pkgs.lib.makeLibraryPath [
      # Needed for pandas / numpy
      pkgs.stdenv.cc.cc.lib
      pkgs.zlib
      # Needed for pygame
      pkgs.glib
      # Needed for matplotlib
      pkgs.xorg.libX11
    ];
    PYTHONHOME = "${pkgs.python310Full}";
    PYTHONBIN = "${pkgs.python310Full}/bin/python3.10";
    LANG = "en_US.UTF-8";
    STDERREDBIN = "${pkgs.replitPackages.stderred}/bin/stderred";
    PRYBAR_PYTHON_BIN = "${pkgs.replitPackages.prybar-python310}/bin/prybar-python310";
  };
}

.replit

# The command that runs the program. If the interpreter field is set, it will have priority and this run command will do nothing
run = "python3 main.py"

# The primary language of the repl. There can be others, though!
language = "python3"
entrypoint = "main.py"
# A list of globs that specify which files and directories should
# be hidden in the workspace.
hidden = ["venv", ".config", "**/__pycache__", "**/.mypy_cache", "**/*.pyc"]

# Specifies which nix channel to use when building the environment.
[nix]
channel = "stable-22_11"

# The command to start the interpreter.
[interpreter]
  [interpreter.command]
  args = [
    "stderred",
    "--",
    "prybar-python310",
    "-q",
    "--ps1",
    "\u0001\u001b[33m\u0002\u0001\u001b[00m\u0002 ",
    "-i",
  ]
  env = { LD_LIBRARY_PATH = "$PYTHON_LD_LIBRARY_PATH" }

[env]
VIRTUAL_ENV = "${REPL_HOME}/venv"
PATH = "${VIRTUAL_ENV}/bin"
PYTHONPATH = "$PYTHONHOME/lib/python3.10:${VIRTUAL_ENV}/lib/python3.10/site-packages"
REPLIT_POETRY_PYPI_REPOSITORY = "https://package-proxy.replit.com/pypi/"
MPLBACKEND = "TkAgg"
POETRY_CACHE_DIR = "${REPL_HOME}/.cache/pypoetry"

# Enable unit tests. This is only supported for a few languages.
[unitTest]
language = "python3"

# Add a debugger!
[debugger]
support = true

  # How to start the debugger.
  [debugger.interactive]
  transport = "localhost:0"
  startCommand = ["dap-python", "main.py"]

    # How to communicate with the debugger.
    [debugger.interactive.integratedAdapter]
    dapTcpAddress = "localhost:0"

    # How to tell the debugger to start a debugging session.
    [debugger.interactive.initializeMessage]
    command = "initialize"
    type = "request"

      [debugger.interactive.initializeMessage.arguments]
      adapterID = "debugpy"
      clientID = "replit"
      clientName = "replit.com"
      columnsStartAt1 = true
      linesStartAt1 = true
      locale = "en-us"
      pathFormat = "path"
      supportsInvalidatedEvent = true
      supportsProgressReporting = true
      supportsRunInTerminalRequest = true
      supportsVariablePaging = true
      supportsVariableType = true

    # How to tell the debugger to start the debuggee application.
    [debugger.interactive.launchMessage]
    command = "attach"
    type = "request"

      [debugger.interactive.launchMessage.arguments]
      logging = {}

# Configures the packager.
[packager]
language = "python3"
ignoredPackages = ["unit_tests"]

  [packager.features]
  enabledForHosting = false
  # Enable searching packages from the sidebar.
  packageSearch = true
  # Enable guessing what packages are needed from the code.
  guessImports = true

# These are the files that need to be preserved when this 
# language template is used as the base language template
# for Python repos imported from GitHub
[gitHubImport]
requiredFiles = [".replit", "replit.nix", ".config", "venv"]

[languages]

[languages.python3]
pattern = "**/*.py"

[languages.python3.languageServer]
start = "pylsp"

[deployment]
run = ["sh", "-c", "python3 main.py"]
2 Likes

Same here. Python input/output tests are not working. Tried to copy contents of .replit and replit.nix but still not working.

2 Likes

Problem description:*
Hi, My tests newly created are not working…:frowning:
Please see here… unsure why.
I’ve created tests before and they work fine.

Expected behavior:
(test passed)
John Smith (in output box)

Actual behavior:
no output recorded in test.

Steps to reproduce:

f = "John"
l = "Smith"
print (f, l)

in test, Match then output = John Smith
Same as example here: https://docs.replit.com/teams-edu/input-output-testing

Bug appears at this link:
https://replit.com/@9d-2324/asdad

**Browser:
OS: Chrome