0
0
Testing Fundamentalstesting~10 mins

Test environment setup in Testing Fundamentals - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to set the test environment variable.

Testing Fundamentals
import os
os.environ[[1]] = 'test'
Drag options to blanks, or click blank then click option'
A'TEST_ENV'
B'PROD_ENV'
C'ENV_MODE'
D'DEBUG_MODE'
Attempts:
3 left
💡 Hint
Common Mistakes
Using production or debug environment names instead of test environment.
Forgetting to use quotes around the environment variable name.
2fill in blank
medium

Complete the code to initialize the test database connection.

Testing Fundamentals
def setup_database():
    connection = create_connection([1])
    return connection
Drag options to blanks, or click blank then click option'
A'prod_db_url'
B'backup_db_url'
C'dev_db_url'
D'test_db_url'
Attempts:
3 left
💡 Hint
Common Mistakes
Using production database URL in tests.
Confusing development and test database URLs.
3fill in blank
hard

Fix the error in the test environment cleanup function.

Testing Fundamentals
def cleanup():
    if os.path.exists([1]):
        os.remove('test_data.db')
Drag options to blanks, or click blank then click option'
A'prod_data.db'
B'backup_data.db'
C'test_data.db'
D'temp_data.db'
Attempts:
3 left
💡 Hint
Common Mistakes
Checking for a different file than the one being removed.
Using production or backup filenames instead of test filenames.
4fill in blank
hard

Fill both blanks to create a test configuration dictionary with environment and debug mode.

Testing Fundamentals
test_config = {
    'environment': [1],
    'debug': [2]
}
Drag options to blanks, or click blank then click option'
A'test'
BTrue
CFalse
D'production'
Attempts:
3 left
💡 Hint
Common Mistakes
Setting environment to 'production' instead of 'test'.
Setting debug mode to False during testing.
5fill in blank
hard

Fill all three blanks to define a test setup function that sets environment, initializes database, and returns config.

Testing Fundamentals
def test_setup():
    env = [1]
    db = create_connection([2])
    config = {'env': env, 'db': db, 'debug': [3]
    return config
Drag options to blanks, or click blank then click option'
A'test'
B'test_db_url'
CTrue
D'prod'
Attempts:
3 left
💡 Hint
Common Mistakes
Using production environment or database URL in test setup.
Setting debug mode to False.