Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create documents for local testing #845

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
Open
77 changes: 77 additions & 0 deletions doc/dev/testing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# Setting up a local testing environment
andrewqian2001datadog marked this conversation as resolved.
Show resolved Hide resolved

### Install dependencies
Inside the repo, set up a virtual environment and install dependencies from the command line:
* `python -m venv .venv`
* `source .venv/bin/activate`
* `pip install -e .`
* `pip install pytest`
* `pip install mock`

### Create config files
Create a folder called `./vscode`.
Inside the folder, create a file called `launch.json` with the following settings:
```
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Python Debugger: Current File",
"type": "debugpy",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal"
}
]
}
```
Create a file called `settings.json` with the following settings:
```
{
"python.testing.unittestArgs": [
"-v",
"-s",
"./tests",
"-p",
"test_*.py"
],
"python.testing.pytestEnabled": false,
"python.testing.unittestEnabled": true
}
```
### Run unit tests locally in VS Code
You should now be able to run the unit tests locally:

<img width="604" alt="image" src="https://github.com/user-attachments/assets/ea5c74c5-ee56-4fc3-83c8-73a00c9cab1e">

### Send logs to the agent
andrewqian2001datadog marked this conversation as resolved.
Show resolved Hide resolved
Create a folder for testing, such as `testapp/main.py`. Create a file inside the folder with the following code:
```
from datadog import initialize, statsd
import time

options = {
"statsd_host": "127.0.0.1",
"statsd_port": 8125,
}

initialize(**options)


while(1):
statsd.increment('example_metric.increment', tags=["environment:dev"])
statsd.decrement('example_metric.decrement', tags=["environment:dev"])
time.sleep(10)
```

[Install the Agent](https://github.com/DataDog/datadog-agent).

Run the Agent: `./bin/agent/agent run -c bin/agent/dist/datadog.yaml`

Inside the `main.py` file that you just created, run the debugger to send logs to the agent.
andrewqian2001datadog marked this conversation as resolved.
Show resolved Hide resolved

Those logs should appear in the [Log Explorer](https://dddev.datadoghq.com/logs?query=&agg_m=count&agg_m_source=base&agg_t=count&cols=host%2Cservice&fromUser=true&messageDisplay=inline&refresh_mode=sliding&storage=hot&stream_sort=desc&viz=stream&from_ts=1722966102377&to_ts=1722967002377&live=true) in Datadog
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's remove this line. It links to an internal org that external contributors cant view. (also this doc refers mostly to metrics, and this points to the logs explorer)


Loading