import glob
import json
import os
import time


import pytest

from helpers import solutions_dir


# NOTE: If we make solution files a fixture instead of a normal attr/function,
# then we can't use it in pytest's parametrize
solution_files = glob.glob(os.path.join(solutions_dir("python"), "*.py"))


@pytest.mark.python
def test_solutions_exist():
    assert solution_files


# TODO ids. id function to turn file name into cleaner label
@pytest.mark.python
@pytest.mark.parametrize("solution_file", solution_files)
def test_submit_file(solution_file, submit_solution):
    result = submit_solution(solution_file)

    assert result.get("success") is True, "Failed. Engine output:\n{:}".format(
        json.dumps(result, indent=4)
    )

import glob
import json
import os
import time


import pytest

from helpers import solutions_dir


# NOTE: If we make solution_files a fixture instead of a normal attr/function,
# then we can't use it in pytest's parametrize
solution_files = glob.glob(os.path.join(solutions_dir("python"), "*.py"))


@pytest.mark.python
def test_solutions_exist():
    assert solution_files


def id_func(param):
    problem_name, ext = os.path.splitext(os.path.basename(param))
    return problem_name


@pytest.mark.python
@pytest.mark.parametrize("solution_file", solution_files, ids=id_func)
def test_submit_file(solution_file, submit_solution):
    result = submit_solution(solution_file)

    assert result.get("success") is True, "Failed. Engine output:\n{:}".format(
        json.dumps(result, indent=4)
    )

Add ids to parametrized tests
Add ids to parametrized tests

  import glob
  import json
  import os
  import time
  
  
  import pytest
  
  from helpers import solutions_dir
  
  
- # NOTE: If we make solution files a fixture instead of a normal attr/function,
+ # NOTE: If we make solution_files a fixture instead of a normal attr/function,
  # then we can't use it in pytest's parametrize
  solution_files = glob.glob(os.path.join(solutions_dir("python"), "*.py"))
  
  
  @pytest.mark.python
  def test_solutions_exist():
      assert solution_files
  
  
- # TODO ids. id function to turn file name into cleaner label
+ def id_func(param):
+     problem_name, ext = os.path.splitext(os.path.basename(param))
+     return problem_name
+ 
+ 
  @pytest.mark.python
- @pytest.mark.parametrize("solution_file", solution_files)
+ @pytest.mark.parametrize("solution_file", solution_files, ids=id_func)
  def test_submit_file(solution_file, submit_solution):
      result = submit_solution(solution_file)
  
      assert result.get("success") is True, "Failed. Engine output:\n{:}".format(
          json.dumps(result, indent=4)
      )
  
Add ids to parametrized tests
## Code Before:
import glob
import json
import os
import time


import pytest

from helpers import solutions_dir


# NOTE: If we make solution files a fixture instead of a normal attr/function,
# then we can't use it in pytest's parametrize
solution_files = glob.glob(os.path.join(solutions_dir("python"), "*.py"))


@pytest.mark.python
def test_solutions_exist():
    assert solution_files


# TODO ids. id function to turn file name into cleaner label
@pytest.mark.python
@pytest.mark.parametrize("solution_file", solution_files)
def test_submit_file(solution_file, submit_solution):
    result = submit_solution(solution_file)

    assert result.get("success") is True, "Failed. Engine output:\n{:}".format(
        json.dumps(result, indent=4)
    )

## Instruction:
Add ids to parametrized tests
## Code After:
import glob
import json
import os
import time


import pytest

from helpers import solutions_dir


# NOTE: If we make solution_files a fixture instead of a normal attr/function,
# then we can't use it in pytest's parametrize
solution_files = glob.glob(os.path.join(solutions_dir("python"), "*.py"))


@pytest.mark.python
def test_solutions_exist():
    assert solution_files


def id_func(param):
    problem_name, ext = os.path.splitext(os.path.basename(param))
    return problem_name


@pytest.mark.python
@pytest.mark.parametrize("solution_file", solution_files, ids=id_func)
def test_submit_file(solution_file, submit_solution):
    result = submit_solution(solution_file)

    assert result.get("success") is True, "Failed. Engine output:\n{:}".format(
        json.dumps(result, indent=4)
    )
